[patch 2/3] PS3: Add logical performance monitor device support

STALE6804d

3 messages, 2 authors, 2008-01-06 · open the first message on its own page

[patch 2/3] PS3: Add logical performance monitor device support

From: Geoff Levand <hidden>
Date: 2008-01-05 03:13:57

Add PS3 logical performance monitor (lpm) device support to the
PS3 system-bus and platform device registration routines.

Signed-off-by: Geoff Levand <redacted>
---
 arch/powerpc/platforms/ps3/device-init.c |   95 ++++++++++++++++++++++++++++++-
 arch/powerpc/platforms/ps3/system-bus.c  |    5 +
 include/asm-powerpc/ps3.h                |    7 ++
 3 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/platforms/ps3/lpm.c
--- a/arch/powerpc/platforms/ps3/device-init.c
+++ b/arch/powerpc/platforms/ps3/device-init.c
@@ -30,6 +30,97 @@
 
 #include "platform.h"
 
+static int __init ps3_register_lpm_devices(void)
+{
+	int result;
+	unsigned int pu_count;
+	u64 tmp1;
+	u64 tmp2;
+	struct layout {
+		struct ps3_system_bus_device dev;
+	} *p;
+
+	pr_debug(" -> %s:%d\n", __func__, __LINE__);
+
+	p = kzalloc(sizeof(*p), GFP_KERNEL);
+	if (!p)
+		return -ENOMEM;
+
+	p->dev.match_id = PS3_MATCH_ID_LPM;
+	p->dev.dev_type = PS3_DEVICE_TYPE_LPM;
+
+	result = ps3_repository_read_num_pu(&pu_count);
+
+	if (result) {
+		pr_debug("%s:%d: ps3_repository_read_num_pu failed \n",
+			__func__, __LINE__);
+		goto fail_read_repo;
+	}
+
+	/* The current lpm driver only supports a single BE processor. */
+
+	if (pu_count > 1) {
+		pr_info("%s:%d: found %u BE processors, only one supported\n",
+			__func__, __LINE__, pu_count);
+	}
+
+	result = ps3_repository_read_pu_id(0, &p->dev.lpm.pu_id);
+
+	if (result) {
+		pr_debug("%s:%d: ps3_repository_read_pu_id failed \n",
+			__func__, __LINE__);
+		goto fail_read_repo;
+	}
+
+	result = ps3_repository_read_lpm_privileges(0, &tmp1,
+		&p->dev.lpm.rights);
+
+	if (result) {
+		pr_debug("%s:%d: ps3_repository_read_lpm_privleges failed \n",
+			__func__, __LINE__);
+		goto fail_read_repo;
+	}
+
+	lv1_get_logical_partition_id(&tmp2);
+
+	if (tmp1 != tmp2) {
+		pr_debug("%s:%d: wrong lpar\n",
+			__func__, __LINE__);
+		result = -1;
+		goto fail_rights;
+	}
+
+	if (!(p->dev.lpm.rights & PS3_LPM_RIGHTS_USE_LPM)) {
+		pr_debug("%s:%d: don't have rights to use lpm\n",
+			__func__, __LINE__);
+		result = -1;
+		goto fail_rights;
+	}
+
+	pr_debug("%s:%d: pu_id %lu, rights %lu(%lxh)\n",
+		__func__, __LINE__, p->dev.lpm.pu_id, p->dev.lpm.rights,
+		p->dev.lpm.rights);
+
+	result = ps3_system_bus_device_register(&p->dev);
+
+	if (result) {
+		pr_debug("%s:%d ps3_system_bus_device_register failed\n",
+			__func__, __LINE__);
+		goto fail_register;
+	}
+
+	pr_debug(" <- %s:%d\n", __func__, __LINE__);
+	return 0;
+
+
+fail_register:
+fail_rights:
+fail_read_repo:
+	kfree(p);
+	pr_debug(" <- %s:%d: failed\n", __func__, __LINE__);
+	return result;
+}
+
 /**
  * ps3_setup_gelic_device - Setup and register a gelic device instance.
  *
@@ -787,6 +878,8 @@ static int __init ps3_register_devices(v
 
 	ps3_register_sound_devices();
 
+	ps3_register_lpm_devices();
+
 	pr_debug(" <- %s:%d\n", __func__, __LINE__);
 	return 0;
 }
--- a/arch/powerpc/platforms/ps3/system-bus.c
+++ b/arch/powerpc/platforms/ps3/system-bus.c
@@ -715,6 +715,7 @@ int ps3_system_bus_device_register(struc
 	static unsigned int dev_ioc0_count;
 	static unsigned int dev_sb_count;
 	static unsigned int dev_vuart_count;
+	static unsigned int dev_lpm_count;
 
 	if (!dev->core.parent)
 		dev->core.parent = &ps3_system_bus;
@@ -737,6 +738,10 @@ int ps3_system_bus_device_register(struc
 		snprintf(dev->core.bus_id, sizeof(dev->core.bus_id),
 			"vuart_%02x", ++dev_vuart_count);
 		break;
+	case PS3_DEVICE_TYPE_LPM:
+		snprintf(dev->core.bus_id, sizeof(dev->core.bus_id),
+			"lpm_%02x", ++dev_lpm_count);
+		break;
 	default:
 		BUG();
 	};
--- a/include/asm-powerpc/ps3.h
+++ b/include/asm-powerpc/ps3.h
@@ -317,6 +317,7 @@ enum ps3_match_id {
 	PS3_MATCH_ID_STOR_FLASH     = 8,
 	PS3_MATCH_ID_SOUND          = 9,
 	PS3_MATCH_ID_GRAPHICS       = 10,
+	PS3_MATCH_ID_LPM            = 11,
 };
 
 #define PS3_MODULE_ALIAS_EHCI           "ps3:1"
@@ -329,11 +330,13 @@ enum ps3_match_id {
 #define PS3_MODULE_ALIAS_STOR_FLASH     "ps3:8"
 #define PS3_MODULE_ALIAS_SOUND          "ps3:9"
 #define PS3_MODULE_ALIAS_GRAPHICS       "ps3:10"
+#define PS3_MODULE_ALIAS_LPM            "ps3:11"
 
 enum ps3_system_bus_device_type {
 	PS3_DEVICE_TYPE_IOC0 = 1,
 	PS3_DEVICE_TYPE_SB,
 	PS3_DEVICE_TYPE_VUART,
+	PS3_DEVICE_TYPE_LPM,
 };
 
 /**
@@ -350,6 +353,10 @@ struct ps3_system_bus_device {
 	struct ps3_dma_region *d_region;  /* SB, IOC0 */
 	struct ps3_mmio_region *m_region; /* SB, IOC0*/
 	unsigned int port_number;         /* VUART */
+	struct {                          /* LPM */
+		u64 pu_id;
+		u64 rights;
+	} lpm;
 
 /*	struct iommu_table *iommu_table; -- waiting for BenH's cleanups */
 	struct device core;
-- 

Re: [patch 2/3] PS3: Add logical performance monitor device support

From: Arnd Bergmann <arnd@arndb.de>
Date: 2008-01-05 11:30:04

T24gU2F0dXJkYXkgMDUgSmFudWFyeSAyMDA4LCBHZW9mZiBMZXZhbmQgd3JvdGU6Cj4gKyAgICAg
ICBzdHJ1Y3QgbGF5b3V0IHsKPiArICAgICAgICAgICAgICAgc3RydWN0IHBzM19zeXN0ZW1fYnVz
X2RldmljZSBkZXY7Cj4gKyAgICAgICB9ICpw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performance monitor device support

From: Geoff Levand <hidden>
Date: 2008-01-06 20:40:48

On 01/05/2008 03:29 AM, Arnd Bergmann wrote:
On Saturday 05 January 2008, Geoff Levand wrote:
quoted
+       struct layout {
+               struct ps3_system_bus_device dev;
+       } *p;
What's the point of this data structure? You don't use the
struct anywhere, and it only has one member, so you could
just declare that directly.
Yes, this code was just cut and pasted from a device that
had more members.
quoted
+       if (tmp1 != tmp2) {
+               pr_debug("%s:%d: wrong lpar\n",
+                       __func__, __LINE__);
+               result = -1;
+               goto fail_rights;
+       }
+
+       if (!(p->dev.lpm.rights & PS3_LPM_RIGHTS_USE_LPM)) {
+               pr_debug("%s:%d: don't have rights to use lpm\n",
+                       __func__, __LINE__);
+               result = -1;
+               goto fail_rights;
+       }
+
I think __init functions should return error codes like -EPERM or
-EINVAL, not numeric -1.
I'll fix it in the next post.

-Geoff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help