Skip to contentSkip to conversation

powerpc/powernv: Use uint64_t instead of size_t in OPAL APIs

PATCH In review Anton Blanchard 2 participants 12 messages Apr 22, 2014 – Apr 23, 2014 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 powerpc/powernv: Use uint64_t instead of size_t in OPAL APIs

Using size_t in our APIs is asking for trouble, especially when some OPAL calls use size_t pointers.

---
 arch/powerpc/include/asm/opal.h            | 12 ++++++------
 arch/powerpc/platforms/powernv/opal-elog.c |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/opal.h +6 -6
index a2efdaa..2a34485 100644
@@ -858,8 +858,8 @@ int64_t opal_lpc_write(uint32_t chip_id, enum OpalLPCAddressType addr_type,
 int64_t opal_lpc_read(uint32_t chip_id, enum OpalLPCAddressType addr_type,
 		      uint32_t addr, __be32 *data, uint32_t sz);
 
-int64_t opal_read_elog(uint64_t buffer, size_t size, uint64_t log_id);
-int64_t opal_get_elog_size(uint64_t *log_id, size_t *size, uint64_t *elog_type);
+int64_t opal_read_elog(uint64_t buffer, uint64_t size, uint64_t log_id);
+int64_t opal_get_elog_size(uint64_t *log_id, uint64_t *size, uint64_t *elog_type);
 int64_t opal_write_elog(uint64_t buffer, uint64_t size, uint64_t offset);
 int64_t opal_send_ack_elog(uint64_t log_id);
 void opal_resend_pending_logs(void);
@@ -874,13 +874,13 @@ int64_t opal_dump_read(uint32_t dump_id, uint64_t buffer);
 int64_t opal_dump_ack(uint32_t dump_id);
 int64_t opal_dump_resend_notification(void);
 
-int64_t opal_get_msg(uint64_t buffer, size_t size);
-int64_t opal_check_completion(uint64_t buffer, size_t size, uint64_t token);
+int64_t opal_get_msg(uint64_t buffer, uint64_t size);
+int64_t opal_check_completion(uint64_t buffer, uint64_t size, uint64_t token);
 int64_t opal_sync_host_reboot(void);
 int64_t opal_get_param(uint64_t token, uint32_t param_id, uint64_t buffer,
-		size_t length);
+		uint64_t length);
 int64_t opal_set_param(uint64_t token, uint32_t param_id, uint64_t buffer,
-		size_t length);
+		uint64_t length);
 int64_t opal_sensor_read(uint32_t sensor_hndl, int token, __be32 *sensor_data);
 
 /* Internal functions */
arch/powerpc/platforms/powernv/opal-elog.c +1 -1
index ef7bc2a..7e3821e 100644
@@ -238,7 +238,7 @@ static struct elog_obj *create_elog_obj(uint64_t id, size_t size, uint64_t type)
 
 static void elog_work_fn(struct work_struct *work)
 {
-	size_t elog_size;
+	uint64_t elog_size;
 	uint64_t log_id;
 	uint64_t elog_type;
 	int rc;
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 2/6 powerpc/powernv: Remove some OPAL function declaration duplication

We had some duplication of the internal OPAL functions.

---
 arch/powerpc/include/asm/opal.h | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/opal.h +2 -10
index 2a34485..cb7d52e 100644
@@ -884,7 +884,8 @@ int64_t opal_set_param(uint64_t token, uint32_t param_id, uint64_t buffer,
 int64_t opal_sensor_read(uint32_t sensor_hndl, int token, __be32 *sensor_data);
 
 /* Internal functions */
-extern int early_init_dt_scan_opal(unsigned long node, const char *uname, int depth, void *data);
+extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
+				   int depth, void *data);
 extern int early_init_dt_scan_recoverable_ranges(unsigned long node,
 				 const char *uname, int depth, void *data);
 
@@ -893,10 +894,6 @@ extern int opal_put_chars(uint32_t vtermno, const char *buf, int total_len);
 
 extern void hvc_opal_init_early(void);
 
-/* Internal functions */
-extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
-				   int depth, void *data);
-
 extern int opal_notifier_register(struct notifier_block *nb);
 extern int opal_notifier_unregister(struct notifier_block *nb);
 
@@ -906,9 +903,6 @@ extern void opal_notifier_enable(void);
 extern void opal_notifier_disable(void);
 extern void opal_notifier_update_evt(uint64_t evt_mask, uint64_t evt_val);
 
-extern int opal_get_chars(uint32_t vtermno, char *buf, int count);
-extern int opal_put_chars(uint32_t vtermno, const char *buf, int total_len);
-
 extern int __opal_async_get_token(void);
 extern int opal_async_get_token_interruptible(void);
 extern int __opal_async_release_token(int token);
@@ -916,8 +910,6 @@ extern int opal_async_release_token(int token);
 extern int opal_async_wait_response(uint64_t token, struct opal_msg *msg);
 extern int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data);
 
-extern void hvc_opal_init_early(void);
-
 struct rtc_time;
 extern int opal_set_rtc_time(struct rtc_time *tm);
 extern void opal_get_rtc_time(struct rtc_time *tm);
Signature · 1 line
1.8.3.2
#2 lore raw

PATCH 3/6 powerpc/powernv: Fix little endian issues with opal_do_notifier calls

In reply to Anton Blanchard

The bitmap in opal_poll_events and opal_handle_interrupt is big endian, so we need to byteswap it on little endian builds.

---
 arch/powerpc/platforms/powernv/opal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/platforms/powernv/opal.c +3 -3
index 49d2f00..17cfc70 100644
@@ -242,14 +242,14 @@ void opal_notifier_update_evt(uint64_t evt_mask,
 void opal_notifier_enable(void)
 {
 	int64_t rc;
-	uint64_t evt = 0;
+	__be64 evt = 0;
 
 	atomic_set(&opal_notifier_hold, 0);
 
 	/* Process pending events */
 	rc = opal_poll_events(&evt);
 	if (rc == OPAL_SUCCESS && evt)
-		opal_do_notifier(evt);
+		opal_do_notifier(be64_to_cpu(evt));
 }
 
 void opal_notifier_disable(void)
@@ -529,7 +529,7 @@ static irqreturn_t opal_interrupt(int irq, void *data)
 
 	opal_handle_interrupt(virq_to_hw(irq), &events);
 
-	opal_do_notifier(events);
+	opal_do_notifier(be64_to_cpu(events));
 
 	return IRQ_HANDLED;
 }
Signature · 1 line
1.8.3.2
#3 lore raw

PATCH 4/6 powerpc/powernv: Fix little endian issues in OPAL error log code

In reply to Anton Blanchard

Fix little endian issues with the OPAL error log code.

---
 arch/powerpc/include/asm/opal.h            | 2 +-
 arch/powerpc/platforms/powernv/opal-elog.c | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/opal.h +1 -1
index cb7d52e..1a752ac 100644
@@ -859,7 +859,7 @@ int64_t opal_lpc_read(uint32_t chip_id, enum OpalLPCAddressType addr_type,
 		      uint32_t addr, __be32 *data, uint32_t sz);
 
 int64_t opal_read_elog(uint64_t buffer, uint64_t size, uint64_t log_id);
-int64_t opal_get_elog_size(uint64_t *log_id, uint64_t *size, uint64_t *elog_type);
+int64_t opal_get_elog_size(__be64 *log_id, __be64 *size, __be64 *elog_type);
 int64_t opal_write_elog(uint64_t buffer, uint64_t size, uint64_t offset);
 int64_t opal_send_ack_elog(uint64_t log_id);
 void opal_resend_pending_logs(void);
arch/powerpc/platforms/powernv/opal-elog.c +8 -1
index 7e3821e..10268c4 100644
@@ -238,18 +238,25 @@ static struct elog_obj *create_elog_obj(uint64_t id, size_t size, uint64_t type)
 
 static void elog_work_fn(struct work_struct *work)
 {
+	__be64 size;
+	__be64 id;
+	__be64 type;
 	uint64_t elog_size;
 	uint64_t log_id;
 	uint64_t elog_type;
 	int rc;
 	char name[2+16+1];
 
-	rc = opal_get_elog_size(&log_id, &elog_size, &elog_type);
+	rc = opal_get_elog_size(&id, &size, &type);
 	if (rc != OPAL_SUCCESS) {
 		pr_err("ELOG: Opal log read failed\n");
 		return;
 	}
 
+	elog_size = be64_to_cpu(size);
+	log_id = be64_to_cpu(id);
+	elog_type = be64_to_cpu(type);
+
 	BUG_ON(elog_size > OPAL_MAX_ERRLOG_SIZE);
 
 	if (elog_size >= OPAL_MAX_ERRLOG_SIZE)
Signature · 1 line
1.8.3.2
#5 lore raw

PATCH 5/6 powerpc/powernv: Create OPAL sglist helper functions and fix endian issues

In reply to Anton Blanchard

We have two copies of code that creates an OPAL sg list. Consolidate these into a common set of helpers and fix the endian issues.

The flash interface embedded a version number in the num_entries field, whereas the dump interface did did not. Since versioning wasn't added to the flash interface and it is impossible to add this in a backwards compatible way, just remove it.

---
 arch/powerpc/include/asm/opal.h             |  14 ++--
 arch/powerpc/platforms/powernv/opal-dump.c  |  81 +--------------------
 arch/powerpc/platforms/powernv/opal-flash.c | 106 +---------------------------
 arch/powerpc/platforms/powernv/opal.c       |  63 +++++++++++++++++
 4 files changed, 76 insertions(+), 188 deletions(-)
arch/powerpc/include/asm/opal.h +9 -5
index 1a752ac..afb0fed 100644
@@ -41,14 +41,14 @@ struct opal_takeover_args {
  * size except the last one in the list to be as well.
  */
 struct opal_sg_entry {
-	void    *data;
-	long    length;
+	__be64 data;
+	__be64 length;
 };
 
-/* sg list */
+/* SG list */
 struct opal_sg_list {
-	unsigned long num_entries;
-	struct opal_sg_list *next;
+	__be64 length;
+	__be64 next;
 	struct opal_sg_entry entry[];
 };
 
@@ -929,6 +929,10 @@ extern int opal_resync_timebase(void);
 
 extern void opal_lpc_init(void);
 
+struct opal_sg_list *opal_vmalloc_to_sg_list(void *vmalloc_addr,
+					     unsigned long vmalloc_size);
+void opal_free_sg_list(struct opal_sg_list *sg);
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __OPAL_H */
arch/powerpc/platforms/powernv/opal-dump.c +2 -79

104 lines not on this page · raw message

arch/powerpc/platforms/powernv/opal-flash.c +2 -104

134 lines not on this page · raw message

arch/powerpc/platforms/powernv/opal.c +63 -0

66 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#8 lore raw

PATCH 6/6 powerpc/powernv: Fix little endian issues in OPAL dump code

In reply to Anton Blanchard
---
 arch/powerpc/include/asm/opal.h            |  4 ++--
 arch/powerpc/platforms/powernv/opal-dump.c | 13 +++++++++----
 2 files changed, 11 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/opal.h +2 -2
index afb0fed..66ad7a7 100644
@@ -868,8 +868,8 @@ int64_t opal_validate_flash(uint64_t buffer, uint32_t *size, uint32_t *result);
 int64_t opal_manage_flash(uint8_t op);
 int64_t opal_update_flash(uint64_t blk_list);
 int64_t opal_dump_init(uint8_t dump_type);
-int64_t opal_dump_info(uint32_t *dump_id, uint32_t *dump_size);
-int64_t opal_dump_info2(uint32_t *dump_id, uint32_t *dump_size, uint32_t *dump_type);
+int64_t opal_dump_info(__be32 *dump_id, __be32 *dump_size);
+int64_t opal_dump_info2(__be32 *dump_id, __be32 *dump_size, __be32 *dump_type);
 int64_t opal_dump_read(uint32_t dump_id, uint64_t buffer);
 int64_t opal_dump_ack(uint32_t dump_id);
 int64_t opal_dump_resend_notification(void);
arch/powerpc/platforms/powernv/opal-dump.c +9 -4
index f0b4724..788a197 100644
@@ -209,15 +209,20 @@ static struct kobj_type dump_ktype = {
 	.default_attrs = dump_default_attrs,
 };
 
-static int64_t dump_read_info(uint32_t *id, uint32_t *size, uint32_t *type)
+static int64_t dump_read_info(uint32_t *dump_id, uint32_t *dump_size, uint32_t *dump_type)
 {
+	__be32 id, size, type;
 	int rc;
-	*type = 0xffffffff;
 
-	rc = opal_dump_info2(id, size, type);
+	type = cpu_to_be32(0xffffffff);
 
+	rc = opal_dump_info2(&id, &size, &type);
 	if (rc == OPAL_PARAMETER)
-		rc = opal_dump_info(id, size);
+		rc = opal_dump_info(&id, &size);
+
+	*dump_id = be32_to_cpu(id);
+	*dump_size = be32_to_cpu(size);
+	*dump_type = be32_to_cpu(type);
 
 	if (rc)
 		pr_warn("%s: Failed to get dump info (%d)\n",
Signature · 1 line
1.8.3.2
#4 lore raw

Re: [PATCH 4/6] powerpc/powernv: Fix little endian issues in OPAL error log code

In reply to Anton Blanchard
Quoted 38 lines · Anton Blanchard

Fix little endian issues with the OPAL error log code.

---
  arch/powerpc/include/asm/opal.h            | 2 +-
  arch/powerpc/platforms/powernv/opal-elog.c | 9 ++++++++-
  2 files changed, 9 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/opal.h +1 -1
index cb7d52e..1a752ac 100644
@@ -859,7 +859,7 @@ int64_t opal_lpc_read(uint32_t chip_id, enum OpalLPCAddressType addr_type,
  		      uint32_t addr, __be32 *data, uint32_t sz);
 
  int64_t opal_read_elog(uint64_t buffer, uint64_t size, uint64_t log_id);
-int64_t opal_get_elog_size(uint64_t *log_id, uint64_t *size, uint64_t *elog_type);
+int64_t opal_get_elog_size(__be64 *log_id, __be64 *size, __be64 *elog_type);
  int64_t opal_write_elog(uint64_t buffer, uint64_t size, uint64_t offset);
  int64_t opal_send_ack_elog(uint64_t log_id);
  void opal_resend_pending_logs(void);
arch/powerpc/platforms/powernv/opal-elog.c +3 -0
index 7e3821e..10268c4 100644
@@ -238,18 +238,25 @@ static struct elog_obj *create_elog_obj(uint64_t id, size_t size, uint64_t type)
 
  static void elog_work_fn(struct work_struct *work)
  {
+	__be64 size;
+	__be64 id;
+	__be64 type;
  	uint64_t elog_size;
  	uint64_t log_id;
  	uint64_t elog_type;
  	int rc;
  	char name[2+16+1];

arch/powerpc/platforms/powernv/opal-elog.c static struct elog_obj *create_elog_obj(uint64_t id, size_t size, uint64_t type) · line 257

Quoted 10 lines
arch/powerpc/platforms/powernv/opal-elog.c +3 -1
 
-	rc = opal_get_elog_size(&log_id, &elog_size, &elog_type);
+	rc = opal_get_elog_size(&id, &size, &type);
  	if (rc != OPAL_SUCCESS) {
  		pr_err("ELOG: Opal log read failed\n");
  		return;
  	}
 
+	elog_size = be64_to_cpu(size);
+	log_id = be64_to_cpu(id);

Anton,

Shouldn't we covert Log ID back to BE format in ACK function (elog_ack_store() ) ?

Rest looks good.

-Vasant

Quoted 6 lines
arch/powerpc/platforms/powernv/opal-elog.c +2 -0
+	elog_type = be64_to_cpu(type);
+
  	BUG_ON(elog_size > OPAL_MAX_ERRLOG_SIZE);
 
  	if (elog_size >= OPAL_MAX_ERRLOG_SIZE)
#9 lore raw

Re: [PATCH 6/6] powerpc/powernv: Fix little endian issues in OPAL dump code

In reply to Anton Blanchard
Quoted 11 lines · Anton Blanchard
---
  arch/powerpc/include/asm/opal.h            |  4 ++--
  arch/powerpc/platforms/powernv/opal-dump.c | 13 +++++++++----
  2 files changed, 11 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/opal.h +0 -0
index afb0fed..66ad7a7 100644

arch/powerpc/include/asm/opal.h int64_t opal_validate_flash(uint64_t buffer, uint32_t *size, uint32_t *result); · line 874

Quoted 9 lines
arch/powerpc/include/asm/opal.h +2 -2
@@ -868,8 +868,8 @@ int64_t opal_validate_flash(uint64_t buffer, uint32_t *size, uint32_t *result);
  int64_t opal_manage_flash(uint8_t op);
  int64_t opal_update_flash(uint64_t blk_list);
  int64_t opal_dump_init(uint8_t dump_type);
-int64_t opal_dump_info(uint32_t *dump_id, uint32_t *dump_size);
-int64_t opal_dump_info2(uint32_t *dump_id, uint32_t *dump_size, uint32_t *dump_type);
+int64_t opal_dump_info(__be32 *dump_id, __be32 *dump_size);
+int64_t opal_dump_info2(__be32 *dump_id, __be32 *dump_size, __be32 *dump_type);
  int64_t opal_dump_read(uint32_t dump_id, uint64_t buffer);
  int64_t opal_dump_ack(uint32_t dump_id);

Shouldn't we change above two functions as well ?

Quoted 18 lines
arch/powerpc/include/asm/opal.h +0 -0
  int64_t opal_dump_resend_notification(void);
arch/powerpc/platforms/powernv/opal-dump.c +3 -3
index f0b4724..788a197 100644
@@ -209,15 +209,20 @@ static struct kobj_type dump_ktype = {
  	.default_attrs = dump_default_attrs,
  };
 
-static int64_t dump_read_info(uint32_t *id, uint32_t *size, uint32_t *type)
+static int64_t dump_read_info(uint32_t *dump_id, uint32_t *dump_size, uint32_t *dump_type)
  {
+	__be32 id, size, type;
  	int rc;
-	*type = 0xffffffff;
 
-	rc = opal_dump_info2(id, size, type);
+	type = cpu_to_be32(0xffffffff);

arch/powerpc/platforms/powernv/opal-dump.c static struct kobj_type dump_ktype = { · line 226

Quoted 10 lines
arch/powerpc/platforms/powernv/opal-dump.c +6 -1
 
+	rc = opal_dump_info2(&id, &size, &type);
  	if (rc == OPAL_PARAMETER)
-		rc = opal_dump_info(id, size);
+		rc = opal_dump_info(&id, &size);
+
+	*dump_id = be32_to_cpu(id);
+	*dump_size = be32_to_cpu(size);
+	*dump_type = be32_to_cpu(type);
 

Should we convert ID back to BE format in dump_send_ack() ?

-Vasant

Quoted 3 lines
arch/powerpc/platforms/powernv/opal-dump.c +0 -0
  	if (rc)
  		pr_warn("%s: Failed to get dump info (%d)\n",
#6 lore raw

Re: [PATCH 5/6] powerpc/powernv: Create OPAL sglist helper functions and fix endian issues

In reply to Anton Blanchard
Quoted 154 lines · Anton Blanchard

We have two copies of code that creates an OPAL sg list. Consolidate these into a common set of helpers and fix the endian issues.

The flash interface embedded a version number in the num_entries field, whereas the dump interface did did not. Since versioning wasn't added to the flash interface and it is impossible to add this in a backwards compatible way, just remove it.

---
  arch/powerpc/include/asm/opal.h             |  14 ++--
  arch/powerpc/platforms/powernv/opal-dump.c  |  81 +--------------------
  arch/powerpc/platforms/powernv/opal-flash.c | 106 +---------------------------
  arch/powerpc/platforms/powernv/opal.c       |  63 +++++++++++++++++
  4 files changed, 76 insertions(+), 188 deletions(-)
arch/powerpc/include/asm/opal.h +9 -5
index 1a752ac..afb0fed 100644
@@ -41,14 +41,14 @@ struct opal_takeover_args {
   * size except the last one in the list to be as well.
   */
  struct opal_sg_entry {
-	void    *data;
-	long    length;
+	__be64 data;
+	__be64 length;
  };
 
-/* sg list */
+/* SG list */
  struct opal_sg_list {
-	unsigned long num_entries;
-	struct opal_sg_list *next;
+	__be64 length;
+	__be64 next;
  	struct opal_sg_entry entry[];
  };
 
@@ -929,6 +929,10 @@ extern int opal_resync_timebase(void);
 
  extern void opal_lpc_init(void);
 
+struct opal_sg_list *opal_vmalloc_to_sg_list(void *vmalloc_addr,
+					     unsigned long vmalloc_size);
+void opal_free_sg_list(struct opal_sg_list *sg);
+
  #endif /* __ASSEMBLY__ */
 
  #endif /* __OPAL_H */
arch/powerpc/platforms/powernv/opal-dump.c +1 -78
index b9827b0..f0b4724 100644
@@ -209,80 +209,6 @@ static struct kobj_type dump_ktype = {
  	.default_attrs = dump_default_attrs,
  };
 
-static void free_dump_sg_list(struct opal_sg_list *list)
-{
-	struct opal_sg_list *sg1;
-	while (list) {
-		sg1 = list->next;
-		kfree(list);
-		list = sg1;
-	}
-	list = NULL;
-}
-
-static struct opal_sg_list *dump_data_to_sglist(struct dump_obj *dump)
-{
-	struct opal_sg_list *sg1, *list = NULL;
-	void *addr;
-	int64_t size;
-
-	addr = dump->buffer;
-	size = dump->size;
-
-	sg1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
-	if (!sg1)
-		goto nomem;
-
-	list = sg1;
-	sg1->num_entries = 0;
-	while (size > 0) {
-		/* Translate virtual address to physical address */
-		sg1->entry[sg1->num_entries].data =
-			(void *)(vmalloc_to_pfn(addr) << PAGE_SHIFT);
-
-		if (size > PAGE_SIZE)
-			sg1->entry[sg1->num_entries].length = PAGE_SIZE;
-		else
-			sg1->entry[sg1->num_entries].length = size;
-
-		sg1->num_entries++;
-		if (sg1->num_entries >= SG_ENTRIES_PER_NODE) {
-			sg1->next = kzalloc(PAGE_SIZE, GFP_KERNEL);
-			if (!sg1->next)
-				goto nomem;
-
-			sg1 = sg1->next;
-			sg1->num_entries = 0;
-		}
-		addr += PAGE_SIZE;
-		size -= PAGE_SIZE;
-	}
-	return list;
-
-nomem:
-	pr_err("%s : Failed to allocate memory\n", __func__);
-	free_dump_sg_list(list);
-	return NULL;
-}
-
-static void sglist_to_phy_addr(struct opal_sg_list *list)
-{
-	struct opal_sg_list *sg, *next;
-
-	for (sg = list; sg; sg = next) {
-		next = sg->next;
-		/* Don't translate NULL pointer for last entry */
-		if (sg->next)
-			sg->next = (struct opal_sg_list *)__pa(sg->next);
-		else
-			sg->next = NULL;
-
-		/* Convert num_entries to length */
-		sg->num_entries =
-			sg->num_entries * sizeof(struct opal_sg_entry) + 16;
-	}
-}
-
  static int64_t dump_read_info(uint32_t *id, uint32_t *size, uint32_t *type)
  {
  	int rc;
@@ -314,15 +240,12 @@ static int64_t dump_read_data(struct dump_obj *dump)
  	}
 
  	/* Generate SG list */
-	list = dump_data_to_sglist(dump);
+	list = opal_vmalloc_to_sg_list(dump->buffer, dump->size);
  	if (!list) {
  		rc = -ENOMEM;
  		goto out;
  	}
 
-	/* Translate sg list addr to real address */
-	sglist_to_phy_addr(list);
-
  	/* First entry address */
  	addr = __pa(list);
 

arch/powerpc/platforms/powernv/opal-dump.c static int64_t dump_read_data(struct dump_obj *dump) · line 265

Quoted 2 lines
arch/powerpc/platforms/powernv/opal-dump.c +0 -0
@@ -341,7 +264,7 @@ static int64_t dump_read_data(struct dump_obj *dump)
  			__func__, dump->id);
 

Shouldn't we convert addr and id before passing to opal_dump_read() here ?

Quoted 204 lines
arch/powerpc/platforms/powernv/opal-dump.c +1 -1
  	/* Free SG list */
-	free_dump_sg_list(list);
+	opal_free_sg_list(list);
 
  out:
  	return rc;
arch/powerpc/platforms/powernv/opal-flash.c +2 -104
index 714ef97..0ae9e5f 100644
@@ -79,9 +79,6 @@
  /* XXX: Assume candidate image size is <= 1GB */
  #define MAX_IMAGE_SIZE	0x40000000
 
-/* Flash sg list version */
-#define SG_LIST_VERSION (1UL)
-
  /* Image status */
  enum {
  	IMAGE_INVALID,
@@ -268,93 +265,11 @@ static ssize_t manage_store(struct kobject *kobj,
  }
 
  /*
- * Free sg list
- */
-static void free_sg_list(struct opal_sg_list *list)
-{
-	struct opal_sg_list *sg1;
-	while (list) {
-		sg1 = list->next;
-		kfree(list);
-		list = sg1;
-	}
-	list = NULL;
-}
-
-/*
- * Build candidate image scatter gather list
- *
- * list format:
- *   -----------------------------------
- *  |  VER (8) | Entry length in bytes  |
- *   -----------------------------------
- *  |  Pointer to next entry            |
- *   -----------------------------------
- *  |  Address of memory area 1         |
- *   -----------------------------------
- *  |  Length of memory area 1          |
- *   -----------------------------------
- *  |   .........                       |
- *   -----------------------------------
- *  |   .........                       |
- *   -----------------------------------
- *  |  Address of memory area N         |
- *   -----------------------------------
- *  |  Length of memory area N          |
- *   -----------------------------------
- */
-static struct opal_sg_list *image_data_to_sglist(void)
-{
-	struct opal_sg_list *sg1, *list = NULL;
-	void *addr;
-	int size;
-
-	addr = image_data.data;
-	size = image_data.size;
-
-	sg1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
-	if (!sg1)
-		return NULL;
-
-	list = sg1;
-	sg1->num_entries = 0;
-	while (size > 0) {
-		/* Translate virtual address to physical address */
-		sg1->entry[sg1->num_entries].data =
-			(void *)(vmalloc_to_pfn(addr) << PAGE_SHIFT);
-
-		if (size > PAGE_SIZE)
-			sg1->entry[sg1->num_entries].length = PAGE_SIZE;
-		else
-			sg1->entry[sg1->num_entries].length = size;
-
-		sg1->num_entries++;
-		if (sg1->num_entries >= SG_ENTRIES_PER_NODE) {
-			sg1->next = kzalloc(PAGE_SIZE, GFP_KERNEL);
-			if (!sg1->next) {
-				pr_err("%s : Failed to allocate memory\n",
-				       __func__);
-				goto nomem;
-			}
-
-			sg1 = sg1->next;
-			sg1->num_entries = 0;
-		}
-		addr += PAGE_SIZE;
-		size -= PAGE_SIZE;
-	}
-	return list;
-nomem:
-	free_sg_list(list);
-	return NULL;
-}
-
-/*
   * OPAL update flash
   */
  static int opal_flash_update(int op)
  {
-	struct opal_sg_list *sg, *list, *next;
+	struct opal_sg_list *list;
  	unsigned long addr;
  	int64_t rc = OPAL_PARAMETER;
 
@@ -364,30 +279,13 @@ static int opal_flash_update(int op)
  		goto flash;
  	}
 
-	list = image_data_to_sglist();
+	list = opal_vmalloc_to_sg_list(image_data.data, image_data.size);
  	if (!list)
  		goto invalid_img;
 
  	/* First entry address */
  	addr = __pa(list);
 
-	/* Translate sg list address to absolute */
-	for (sg = list; sg; sg = next) {
-		next = sg->next;
-		/* Don't translate NULL pointer for last entry */
-		if (sg->next)
-			sg->next = (struct opal_sg_list *)__pa(sg->next);
-		else
-			sg->next = NULL;
-
-		/*
-		 * Convert num_entries to version/length format
-		 * to satisfy OPAL.
-		 */
-		sg->num_entries = (SG_LIST_VERSION << 56) |
-			(sg->num_entries * sizeof(struct opal_sg_entry) + 16);
-	}
-
  	pr_alert("FLASH: Image is %u bytes\n", image_data.size);
  	pr_alert("FLASH: Image update requested\n");
  	pr_alert("FLASH: Image will be updated during system reboot\n");
arch/powerpc/platforms/powernv/opal.c +49 -0
index 17cfc70..360ad80c 100644
@@ -638,3 +638,66 @@ void opal_shutdown(void)
 
  /* Export this so that test modules can use it */
  EXPORT_SYMBOL_GPL(opal_invalid_call);
+
+/* Convert a region of vmalloc memory to an opal sg list */
+struct opal_sg_list *opal_vmalloc_to_sg_list(void *vmalloc_addr,
+					     unsigned long vmalloc_size)
+{
+	struct opal_sg_list *sg, *first = NULL;
+	unsigned long i = 0;
+
+	sg = kzalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!sg)
+		goto nomem;
+
+	first = sg;
+
+	while (vmalloc_size > 0) {
+		uint64_t data = vmalloc_to_pfn(vmalloc_addr) << PAGE_SHIFT;
+		uint64_t length = min(vmalloc_size, PAGE_SIZE);
+
+		sg->entry[i].data = cpu_to_be64(data);
+		sg->entry[i].length = cpu_to_be64(length);
+		i++;
+
+		if (i >= SG_ENTRIES_PER_NODE) {
+			struct opal_sg_list *next;
+
+			next = kzalloc(PAGE_SIZE, GFP_KERNEL);
+			if (!next)
+				goto nomem;
+
+			sg->length = cpu_to_be64(
+					i * sizeof(struct opal_sg_entry) + 16);
+			i = 0;
+			sg->next = cpu_to_be64(__pa(next));
+			sg = next;
+		}
+
+		vmalloc_addr += length;
+		vmalloc_size -= length;
+	}
+
+	sg->length = cpu_to_be64(i * sizeof(struct opal_sg_entry) + 16);
+
+	return first;
+
+nomem:
+	pr_err("%s : Failed to allocate memory\n", __func__);
+	opal_free_sg_list(first);
+	return NULL;
+}

arch/powerpc/platforms/powernv/opal.c void opal_shutdown(void) · line 699

Quoted 10 lines
arch/powerpc/platforms/powernv/opal.c +10 -0
+
+void opal_free_sg_list(struct opal_sg_list *sg)
+{
+	while (sg) {
+		uint64_t next = be64_to_cpu(sg->next);
+
+		kfree(sg);
+
+		if (next)
+			sg = __va(next);

This for this fix..

-Vasant

Quoted 5 lines
arch/powerpc/platforms/powernv/opal.c +4 -0
+		else
+			sg = NULL;
+	}
+}
#10 lore raw

Re: [PATCH 6/6] powerpc/powernv: Fix little endian issues in OPAL dump code

In reply to Vasant Hegde

Hi,

Quoted 8 lines
arch/powerpc/include/asm/opal.h +2 -2
-int64_t opal_dump_info(uint32_t *dump_id, uint32_t *dump_size);
-int64_t opal_dump_info2(uint32_t *dump_id, uint32_t *dump_size, uint32_t *dump_type);
+int64_t opal_dump_info(__be32 *dump_id, __be32 *dump_size);
+int64_t opal_dump_info2(__be32 *dump_id, __be32 *dump_size, __be32 *dump_type);
 int64_t opal_dump_read(uint32_t dump_id, uint64_t buffer);
 int64_t opal_dump_ack(uint32_t dump_id);  

Shouldn't we change above two functions as well ?

No, there are no endian issues here because we pass the values via register. The only endian issues are for values we pass via pointer.

Quoted 1 line

Should we convert ID back to BE format in dump_send_ack() ?

Same as above.

Anton

#7 lore raw

Re: [PATCH 5/6] powerpc/powernv: Create OPAL sglist helper functions and fix endian issues

In reply to Vasant Hegde

Hi,

Quoted 2 lines

Shouldn't we convert addr and id before passing to opal_dump_read() here ?

int64_t opal_dump_read(uint32_t dump_id, uint64_t buffer);

All arguments are passed via register, so byteswaping the arguments would break it.

Anton

#11 lore raw

Re: [PATCH 6/6] powerpc/powernv: Fix little endian issues in OPAL dump code

In reply to Anton Blanchard
Quoted 9 lines · Anton Blanchard

Hi,

Quoted 7 lines
arch/powerpc/include/asm/opal.h +2 -2
-int64_t opal_dump_info(uint32_t *dump_id, uint32_t *dump_size);
-int64_t opal_dump_info2(uint32_t *dump_id, uint32_t *dump_size, uint32_t *dump_type);
+int64_t opal_dump_info(__be32 *dump_id, __be32 *dump_size);
+int64_t opal_dump_info2(__be32 *dump_id, __be32 *dump_size, __be32 *dump_type);
  int64_t opal_dump_read(uint32_t dump_id, uint64_t buffer);
  int64_t opal_dump_ack(uint32_t dump_id);
Quoted 5 lines
Quoted 1 line

Shouldn't we change above two functions as well ?

No, there are no endian issues here because we pass the values via register. The only endian issues are for values we pass via pointer.

Anton,

Thanks for the clarification..

-Vasant