Re: [3/3,v3] powerpc/powernv: Add opal-prd channel

2015-06-04 Thread Jeremy Kerr
Hi Michael,

 Sorry, I put this in but then hit the build break, I was going to fix it up 
 but
 would rather you did and tested it, so we may as well do another review :)

whee!

 @@ -0,0 +1,58 @@
 +/*
 + * OPAL Runtime Diagnostics interface driver
 + * Supported on POWERNV platform
 + *
 + * (C) Copyright IBM 2015
 
 Usual syntax is: Copyright IBM Corporation 2015

OK, fixed.

 + *
 + * Author: Vaidyanathan Srinivasan svaidy at linux.vnet.ibm.com
 + * Author: Jeremy Kerr j...@ozlabs.org
 
 I'd rather you dropped these, they'll just bit rot, but if you insist I don't
 care that much.

Yep, I'd rather remove them too.

 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
 + * the Free Software Foundation; either version 2, or (at your option)
 + * any later version.
 
 As pointed out by Daniel, we should probably be using the version 2 only
 language on new files.

Fixed.

 +vma-vm_page_prot = phys_mem_access_prot(file, vma-vm_pgoff,
 + size, vma-vm_page_prot)
 +| _PAGE_SPECIAL;
 
 This doesn't build with CONFIG_STRICT_MM_TYPECHECKS=y:
 
   arch/powerpc/platforms/powernv/opal-prd.c:131:5: error: invalid operands to 
 binary | (have ‘pgprot_t’ and ‘int’)
   | _PAGE_SPECIAL;

OK, new patch coming with the proper pgprot macros.

 +switch(cmd) {
   ^
 space please

Fixed.


 +pr_devel(ioctl SCOM_READ: chip %llx addr %016llx 
 +data %016llx rc %lld\n,
 
 Don't split the string please.

OK, but this makes our lines 80 chars. Assuming that'll be okay.

 +struct file_operations opal_prd_fops = {
 
 This can be static const I think.

Indeed it can! Updated.

 +static struct miscdevice opal_prd_dev = {
 +.minor  = MISC_DYNAMIC_MINOR,
 +.name   = opal-prd,
 +.fops   = opal_prd_fops,
 
 White space is messed up here, should be leading tabs.

[tabs-spaces-both.png]

Thanks for the review, new patch coming soon.

Cheers,


Jeremy


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [3/3,v3] powerpc/powernv: Add opal-prd channel

2015-06-04 Thread Michael Ellerman
On Fri, 2015-29-05 at 03:55:59 UTC, Jeremy Kerr wrote:
 This change adds a char device to access the PRD (processor runtime
 diagnostics) channel to OPAL firmware.
 
 Includes contributions from Vaidyanathan Srinivasan, Neelesh Gupta 
 Vishal Kulkarni.
 
 Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
 Signed-off-by: Jeremy Kerr j...@ozlabs.org
 Acked-by: Stewart Smith stew...@linux.vnet.ibm.com

Sorry, I put this in but then hit the build break, I was going to fix it up but
would rather you did and tested it, so we may as well do another review :)

 diff --git a/arch/powerpc/include/uapi/asm/opal-prd.h 
 b/arch/powerpc/include/uapi/asm/opal-prd.h
 new file mode 100644
 index 000..319ff4a
 --- /dev/null
 +++ b/arch/powerpc/include/uapi/asm/opal-prd.h
 @@ -0,0 +1,58 @@
 +/*
 + * OPAL Runtime Diagnostics interface driver
 + * Supported on POWERNV platform
 + *
 + * (C) Copyright IBM 2015

Usual syntax is: Copyright IBM Corporation 2015

 + *
 + * Author: Vaidyanathan Srinivasan svaidy at linux.vnet.ibm.com
 + * Author: Jeremy Kerr j...@ozlabs.org

I'd rather you dropped these, they'll just bit rot, but if you insist I don't
care that much.

 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
 + * the Free Software Foundation; either version 2, or (at your option)
 + * any later version.

As pointed out by Daniel, we should probably be using the version 2 only
language on new files.

 diff --git a/arch/powerpc/platforms/powernv/opal-prd.c 
 b/arch/powerpc/platforms/powernv/opal-prd.c
 new file mode 100644
 index 000..3004f4a
 --- /dev/null
 +++ b/arch/powerpc/platforms/powernv/opal-prd.c
 @@ -0,0 +1,451 @@

...

 +/*
 + * opal_prd_mmap - maps firmware-provided ranges into userspace
 + * @file: file structure for the device
 + * @vma: VMA to map the registers into
 + */
 +
 +static int opal_prd_mmap(struct file *file, struct vm_area_struct *vma)
 +{
 + size_t addr, size;
 + int rc;
 +
 + pr_devel(opal_prd_mmap(0x%016lx, 0x%016lx, 0x%lx, 0x%lx)\n,
 + vma-vm_start, vma-vm_end, vma-vm_pgoff,
 + vma-vm_flags);
 +
 + addr = vma-vm_pgoff  PAGE_SHIFT;
 + size = vma-vm_end - vma-vm_start;
 +
 + /* ensure we're mapping within one of the allowable ranges */
 + if (!opal_prd_range_is_valid(addr, size))
 + return -EINVAL;
 +
 + vma-vm_page_prot = phys_mem_access_prot(file, vma-vm_pgoff,
 +  size, vma-vm_page_prot)
 + | _PAGE_SPECIAL;

This doesn't build with CONFIG_STRICT_MM_TYPECHECKS=y:

  arch/powerpc/platforms/powernv/opal-prd.c:131:5: error: invalid operands to 
binary | (have ‘pgprot_t’ and ‘int’)
  | _PAGE_SPECIAL;


 +static long opal_prd_ioctl(struct file *file, unsigned int cmd,
 + unsigned long param)
 +{
 + struct opal_prd_info info;
 + struct opal_prd_scom scom;
 + int rc = 0;
 +
 + switch(cmd) {
  ^
  space please

 + case OPAL_PRD_GET_INFO:
 + memset(info, 0, sizeof(info));
 + info.version = OPAL_PRD_KERNEL_VERSION;
 + rc = copy_to_user((void __user *)param, info, sizeof(info));
 + if (rc)
 + return -EFAULT;
 + break;
 +
 + case OPAL_PRD_SCOM_READ:
 + rc = copy_from_user(scom, (void __user *)param, sizeof(scom));
 + if (rc)
 + return -EFAULT;
 +
 + scom.rc = opal_xscom_read(scom.chip, scom.addr,
 + (__be64 *)scom.data);
 + scom.data = be64_to_cpu(scom.data);
 + pr_devel(ioctl SCOM_READ: chip %llx addr %016llx 
 + data %016llx rc %lld\n,

Don't split the string please.

 + scom.chip, scom.addr, scom.data, scom.rc);
 +
 + rc = copy_to_user((void __user *)param, scom, sizeof(scom));
 + if (rc)
 + return -EFAULT;
 + break;
 +
 + case OPAL_PRD_SCOM_WRITE:
 + rc = copy_from_user(scom, (void __user *)param, sizeof(scom));
 + if (rc)
 + return -EFAULT;
 +
 + scom.rc = opal_xscom_write(scom.chip, scom.addr, scom.data);
 + pr_devel(ioctl SCOM_WRITE: chip %llx addr %016llx 
 + data %016llx rc %lld\n,

Don't split the string please.

 + scom.chip, scom.addr, scom.data, scom.rc);
 +
 + rc = copy_to_user((void __user *)param, scom, sizeof(scom));
 + if (rc)
 + return -EFAULT;
 + break;
 +
 + default:
 + rc = -EINVAL;
 + }
 +
 + return rc;
 +}
 +
 +struct file_operations opal_prd_fops = {

This can be static const I think.

 + .open   = opal_prd_open,
 + .mmap   

[PATCH 3/3 v3] powerpc/powernv: Add opal-prd channel

2015-05-28 Thread Jeremy Kerr
This change adds a char device to access the PRD (processor runtime
diagnostics) channel to OPAL firmware.

Includes contributions from Vaidyanathan Srinivasan, Neelesh Gupta 
Vishal Kulkarni.

Signed-off-by: Neelesh Gupta neele...@linux.vnet.ibm.com
Signed-off-by: Jeremy Kerr j...@ozlabs.org
Acked-by: Stewart Smith stew...@linux.vnet.ibm.com

-- 

v3:
 - Add versioning description and reserved fields in opal_prd_info
   for future expansion

 - Fix node leak in opal_prd_range_is_valid

 - Explain open()  probe() semantics

 - Fix miscdev_register error path

---
 arch/powerpc/include/asm/opal-api.h|   21 
 arch/powerpc/include/asm/opal.h|1 
 arch/powerpc/include/uapi/asm/opal-prd.h   |   58 ++
 arch/powerpc/platforms/powernv/Kconfig |7 
 arch/powerpc/platforms/powernv/Makefile|1 
 arch/powerpc/platforms/powernv/opal-prd.c  |  451 +
 arch/powerpc/platforms/powernv/opal-wrappers.S |1 
 arch/powerpc/platforms/powernv/opal.c  |4 
 8 files changed, 542 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/opal-api.h 
b/arch/powerpc/include/asm/opal-api.h
index 0321a90..2407f12 100644
--- a/arch/powerpc/include/asm/opal-api.h
+++ b/arch/powerpc/include/asm/opal-api.h
@@ -153,7 +153,8 @@
 #define OPAL_FLASH_READ110
 #define OPAL_FLASH_WRITE   111
 #define OPAL_FLASH_ERASE   112
-#define OPAL_LAST  112
+#define OPAL_PRD_MSG   113
+#define OPAL_LAST  113
 
 /* Device tree flags */
 
@@ -352,6 +353,7 @@ enum opal_msg_type {
OPAL_MSG_SHUTDOWN,  /* params[0] = 1 reboot, 0 shutdown */
OPAL_MSG_HMI_EVT,
OPAL_MSG_DPO,
+   OPAL_MSG_PRD,
OPAL_MSG_TYPE_MAX,
 };
 
@@ -674,6 +676,23 @@ typedef struct oppanel_line {
__be64 line_len;
 } oppanel_line_t;
 
+enum opal_prd_msg_type {
+   OPAL_PRD_MSG_TYPE_INIT = 0, /* HBRT -- OPAL */
+   OPAL_PRD_MSG_TYPE_FINI, /* HBRT/kernel -- OPAL */
+   OPAL_PRD_MSG_TYPE_ATTN, /* HBRT -- OPAL */
+   OPAL_PRD_MSG_TYPE_ATTN_ACK, /* HBRT -- OPAL */
+   OPAL_PRD_MSG_TYPE_OCC_ERROR,/* HBRT -- OPAL */
+   OPAL_PRD_MSG_TYPE_OCC_RESET,/* HBRT -- OPAL */
+};
+
+struct opal_prd_msg_header {
+   uint8_t type;
+   uint8_t pad[1];
+   __be16  size;
+};
+
+struct opal_prd_msg;
+
 /*
  * SG entries
  *
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 042af1a..93704af 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -193,6 +193,7 @@ int64_t opal_ipmi_recv(uint64_t interface, struct 
opal_ipmi_msg *msg,
uint64_t *msg_len);
 int64_t opal_i2c_request(uint64_t async_token, uint32_t bus_id,
 struct opal_i2c_request *oreq);
+int64_t opal_prd_msg(struct opal_prd_msg *msg);
 
 int64_t opal_flash_read(uint64_t id, uint64_t offset, uint64_t buf,
uint64_t size, uint64_t token);
diff --git a/arch/powerpc/include/uapi/asm/opal-prd.h 
b/arch/powerpc/include/uapi/asm/opal-prd.h
new file mode 100644
index 000..319ff4a
--- /dev/null
+++ b/arch/powerpc/include/uapi/asm/opal-prd.h
@@ -0,0 +1,58 @@
+/*
+ * OPAL Runtime Diagnostics interface driver
+ * Supported on POWERNV platform
+ *
+ * (C) Copyright IBM 2015
+ *
+ * Author: Vaidyanathan Srinivasan svaidy at linux.vnet.ibm.com
+ * Author: Jeremy Kerr j...@ozlabs.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _UAPI_ASM_POWERPC_OPAL_PRD_H_
+#define _UAPI_ASM_POWERPC_OPAL_PRD_H_
+
+#include linux/types.h
+
+/**
+ * The version of the kernel interface of the PRD system. This describes the
+ * interface available for the /dev/opal-prd device. The actual PRD message
+ * layout and content is private to the firmware -- userspace interface, so
+ * is not covered by this versioning.
+ *
+ * Future interface versions are backwards-compatible; if a later kernel
+ * version is encountered, functionality provided in earlier versions
+ * will work.
+ */
+#define OPAL_PRD_KERNEL_VERSION1
+
+#define OPAL_PRD_GET_INFO  _IOR('o', 0x01, struct opal_prd_info)
+#define OPAL_PRD_SCOM_READ _IOR('o', 0x02, struct opal_prd_scom)
+#define OPAL_PRD_SCOM_WRITE_IOW('o', 0x03, struct opal_prd_scom)
+
+#ifndef __ASSEMBLY__
+
+struct opal_prd_info {
+