Re: [PATCH v2 2/8] soc: qcom: smem: Handle big endian CPUs

2015-09-03 Thread Bjorn Andersson
On Wed 02 Sep 15:46 PDT 2015, Stephen Boyd wrote:

> The contents of smem are always in little endian, but the smem
> driver is not capable of being used on big endian CPUs. Annotate
> the little endian data members and update the code to do the
> proper byte swapping.
> 
Reviewed-by: Bjorn Andersson 
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/8] soc: qcom: smem: Handle big endian CPUs

2015-09-02 Thread Stephen Boyd
The contents of smem are always in little endian, but the smem
driver is not capable of being used on big endian CPUs. Annotate
the little endian data members and update the code to do the
proper byte swapping.

Cc: Bjorn Andersson 
Signed-off-by: Stephen Boyd 
---

Changes since v1:
 * Rebased on top of qcom_smem_get() returning a pointer

 drivers/soc/qcom/smem.c | 229 +---
 1 file changed, 138 insertions(+), 91 deletions(-)

diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index e6d0dae63845..74017114ce6e 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -92,9 +92,9 @@
   * @params:   parameters to the command
   */
 struct smem_proc_comm {
-   u32 command;
-   u32 status;
-   u32 params[2];
+   __le32 command;
+   __le32 status;
+   __le32 params[2];
 };
 
 /**
@@ -106,10 +106,10 @@ struct smem_proc_comm {
  * the default region. bits 0,1 are reserved
  */
 struct smem_global_entry {
-   u32 allocated;
-   u32 offset;
-   u32 size;
-   u32 aux_base; /* bits 1:0 reserved */
+   __le32 allocated;
+   __le32 offset;
+   __le32 size;
+   __le32 aux_base; /* bits 1:0 reserved */
 };
 #define AUX_BASE_MASK  0xfffc
 
@@ -125,11 +125,11 @@ struct smem_global_entry {
  */
 struct smem_header {
struct smem_proc_comm proc_comm[4];
-   u32 version[32];
-   u32 initialized;
-   u32 free_offset;
-   u32 available;
-   u32 reserved;
+   __le32 version[32];
+   __le32 initialized;
+   __le32 free_offset;
+   __le32 available;
+   __le32 reserved;
struct smem_global_entry toc[SMEM_ITEM_COUNT];
 };
 
@@ -143,12 +143,12 @@ struct smem_header {
  * @reserved:  reserved entries for later use
  */
 struct smem_ptable_entry {
-   u32 offset;
-   u32 size;
-   u32 flags;
-   u16 host0;
-   u16 host1;
-   u32 reserved[8];
+   __le32 offset;
+   __le32 size;
+   __le32 flags;
+   __le16 host0;
+   __le16 host1;
+   __le32 reserved[8];
 };
 
 /**
@@ -160,13 +160,14 @@ struct smem_ptable_entry {
  * @entry: list of @smem_ptable_entry for the @num_entries partitions
  */
 struct smem_ptable {
-   u32 magic;
-   u32 version;
-   u32 num_entries;
-   u32 reserved[5];
+   u8 magic[4];
+   __le32 version;
+   __le32 num_entries;
+   __le32 reserved[5];
struct smem_ptable_entry entry[];
 };
-#define SMEM_PTABLE_MAGIC  0x434f5424 /* "$TOC" */
+
+static const u8 SMEM_PTABLE_MAGIC[] = { 0x24, 0x54, 0x4f, 0x43 }; /* "$TOC" */
 
 /**
  * struct smem_partition_header - header of the partitions
@@ -181,15 +182,16 @@ struct smem_ptable {
  * @reserved:  for now reserved entries
  */
 struct smem_partition_header {
-   u32 magic;
-   u16 host0;
-   u16 host1;
-   u32 size;
-   u32 offset_free_uncached;
-   u32 offset_free_cached;
-   u32 reserved[3];
+   u8 magic[4];
+   __le16 host0;
+   __le16 host1;
+   __le32 size;
+   __le32 offset_free_uncached;
+   __le32 offset_free_cached;
+   __le32 reserved[3];
 };
-#define SMEM_PART_MAGIC0x54525024 /* "$PRT" */
+
+static const u8 SMEM_PART_MAGIC[] = { 0x24, 0x50, 0x52, 0x54 };
 
 /**
  * struct smem_private_entry - header of each item in the private partition
@@ -201,12 +203,12 @@ struct smem_partition_header {
  * @reserved:  for now reserved entry
  */
 struct smem_private_entry {
-   u16 canary;
-   u16 item;
-   u32 size; /* includes padding bytes */
-   u16 padding_data;
-   u16 padding_hdr;
-   u32 reserved;
+   u16 canary; /* bytes are the same so no swapping needed */
+   __le16 item;
+   __le32 size; /* includes padding bytes */
+   __le16 padding_data;
+   __le16 padding_hdr;
+   __le32 reserved;
 };
 #define SMEM_PRIVATE_CANARY0xa5a5
 
@@ -242,6 +244,45 @@ struct qcom_smem {
struct smem_region regions[0];
 };
 
+static struct smem_private_entry *
+phdr_to_last_private_entry(struct smem_partition_header *phdr)
+{
+   void *p = phdr;
+
+   return p + le32_to_cpu(phdr->offset_free_uncached);
+}
+
+static void *phdr_to_first_cached_entry(struct smem_partition_header *phdr)
+{
+   void *p = phdr;
+
+   return p + le32_to_cpu(phdr->offset_free_cached);
+}
+
+static struct smem_private_entry *
+phdr_to_first_private_entry(struct smem_partition_header *phdr)
+{
+   void *p = phdr;
+
+   return p + sizeof(*phdr);
+}
+
+static struct smem_private_entry *
+private_entry_next(struct smem_private_entry *e)
+{
+   void *p = e;
+
+   return p + sizeof(*e) + le16_to_cpu(e->padding_hdr) +
+  le32_to_cpu(e->size);
+}
+
+static void *entry_to_item(struct smem_private_entry *e)
+{
+   void *p = e;
+
+   return p + sizeof(*e) + le16_to_cpu(e->padding_hdr);
+}
+
 /*