]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/powerpc/platforms/ps3/repository.c
powerpc/ps3: Printing fixups for l64 to ll64 conversion arch/powerpc
[linux-2.6-omap-h63xx.git] / arch / powerpc / platforms / ps3 / repository.c
index ae586a0e5d3f9c75771058b7c22b9279fc8cb237..5e304c292f68e1e22e3fff9dd3527ae8a5f1bcd1 100644 (file)
@@ -33,7 +33,7 @@ enum ps3_lpar_id {
 };
 
 #define dump_field(_a, _b) _dump_field(_a, _b, __func__, __LINE__)
-static void _dump_field(const char *hdr, u64 n, const charfunc, int line)
+static void _dump_field(const char *hdr, u64 n, const char *func, int line)
 {
 #if defined(DEBUG)
        char s[16];
@@ -44,14 +44,14 @@ static void _dump_field(const char *hdr, u64 n, const char* func, int line)
                s[i] = (in[i] <= 126 && in[i] >= 32) ? in[i] : '.';
        s[i] = 0;
 
-       pr_debug("%s:%d: %s%016lx : %s\n", func, line, hdr, n, s);
+       pr_debug("%s:%d: %s%016llx : %s\n", func, line, hdr, n, s);
 #endif
 }
 
 #define dump_node_name(_a, _b, _c, _d, _e) \
        _dump_node_name(_a, _b, _c, _d, _e, __func__, __LINE__)
-static void _dump_node_name (unsigned int lpar_id, u64 n1, u64 n2, u64 n3,
-       u64 n4, const charfunc, int line)
+static void _dump_node_name(unsigned int lpar_id, u64 n1, u64 n2, u64 n3,
+       u64 n4, const char *func, int line)
 {
        pr_debug("%s:%d: lpar: %u\n", func, line, lpar_id);
        _dump_field("n1: ", n1, func, line);
@@ -63,15 +63,15 @@ static void _dump_node_name (unsigned int lpar_id, u64 n1, u64 n2, u64 n3,
 #define dump_node(_a, _b, _c, _d, _e, _f, _g) \
        _dump_node(_a, _b, _c, _d, _e, _f, _g, __func__, __LINE__)
 static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
-       u64 v1, u64 v2, const charfunc, int line)
+       u64 v1, u64 v2, const char *func, int line)
 {
        pr_debug("%s:%d: lpar: %u\n", func, line, lpar_id);
        _dump_field("n1: ", n1, func, line);
        _dump_field("n2: ", n2, func, line);
        _dump_field("n3: ", n3, func, line);
        _dump_field("n4: ", n4, func, line);
-       pr_debug("%s:%d: v1: %016lx\n", func, line, v1);
-       pr_debug("%s:%d: v2: %016lx\n", func, line, v2);
+       pr_debug("%s:%d: v1: %016llx\n", func, line, v1);
+       pr_debug("%s:%d: v2: %016llx\n", func, line, v2);
 }
 
 /**
@@ -138,7 +138,7 @@ static int read_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
                pr_debug("%s:%d: lv1_get_repository_node_value failed: %s\n",
                        __func__, __LINE__, ps3_result(result));
                dump_node_name(lpar_id, n1, n2, n3, n4);
-               return result;
+               return -ENOENT;
        }
 
        dump_node(lpar_id, n1, n2, n3, n4, v1, v2);
@@ -149,13 +149,13 @@ static int read_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
                *_v2 = v2;
 
        if (v1 && !_v1)
-               pr_debug("%s:%d: warning: discarding non-zero v1: %016lx\n",
+               pr_debug("%s:%d: warning: discarding non-zero v1: %016llx\n",
                        __func__, __LINE__, v1);
        if (v2 && !_v2)
-               pr_debug("%s:%d: warning: discarding non-zero v2: %016lx\n",
+               pr_debug("%s:%d: warning: discarding non-zero v2: %016llx\n",
                        __func__, __LINE__, v2);
 
-       return result;
+       return 0;
 }
 
 int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str,
@@ -165,21 +165,18 @@ int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str,
                make_first_field("bus", bus_index),
                make_field(bus_str, 0),
                0, 0,
-               value, 0);
+               value, NULL);
 }
 
-int ps3_repository_read_bus_id(unsigned int bus_index, unsigned int *bus_id)
+int ps3_repository_read_bus_id(unsigned int bus_index, u64 *bus_id)
 {
        int result;
-       u64 v1;
-       u64 v2; /* unused */
 
        result = read_node(PS3_LPAR_ID_PME,
                make_first_field("bus", bus_index),
                make_field("id", 0),
                0, 0,
-               &v1, &v2);
-       *bus_id = v1;
+               bus_id, NULL);
        return result;
 }
 
@@ -193,7 +190,7 @@ int ps3_repository_read_bus_type(unsigned int bus_index,
                make_first_field("bus", bus_index),
                make_field("type", 0),
                0, 0,
-               &v1, 0);
+               &v1, NULL);
        *bus_type = v1;
        return result;
 }
@@ -208,7 +205,7 @@ int ps3_repository_read_bus_num_dev(unsigned int bus_index,
                make_first_field("bus", bus_index),
                make_field("num_dev", 0),
                0, 0,
-               &v1, 0);
+               &v1, NULL);
        *num_dev = v1;
        return result;
 }
@@ -221,22 +218,20 @@ int ps3_repository_read_dev_str(unsigned int bus_index,
                make_field("dev", dev_index),
                make_field(dev_str, 0),
                0,
-               value, 0);
+               value, NULL);
 }
 
 int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index,
-       unsigned int *dev_id)
+       u64 *dev_id)
 {
        int result;
-       u64 v1;
 
        result = read_node(PS3_LPAR_ID_PME,
                make_first_field("bus", bus_index),
                make_field("dev", dev_index),
                make_field("id", 0),
                0,
-               &v1, 0);
-       *dev_id = v1;
+               dev_id, NULL);
        return result;
 }
 
@@ -251,14 +246,14 @@ int ps3_repository_read_dev_type(unsigned int bus_index,
                make_field("dev", dev_index),
                make_field("type", 0),
                0,
-               &v1, 0);
+               &v1, NULL);
        *dev_type = v1;
        return result;
 }
 
 int ps3_repository_read_dev_intr(unsigned int bus_index,
        unsigned int dev_index, unsigned int intr_index,
-       enum ps3_interrupt_type *intr_type, unsigned intinterrupt_id)
+       enum ps3_interrupt_type *intr_type, unsigned int *interrupt_id)
 {
        int result;
        u64 v1;
@@ -287,7 +282,7 @@ int ps3_repository_read_dev_reg_type(unsigned int bus_index,
                make_field("dev", dev_index),
                make_field("reg", reg_index),
                make_field("type", 0),
-               &v1, 0);
+               &v1, NULL);
        *reg_type = v1;
        return result;
 }
@@ -314,324 +309,201 @@ int ps3_repository_read_dev_reg(unsigned int bus_index,
                reg_index, bus_addr, len);
 }
 
-#if defined(DEBUG)
-int ps3_repository_dump_resource_info(unsigned int bus_index,
-       unsigned int dev_index)
-{
-       int result = 0;
-       unsigned int res_index;
 
-       pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
-               bus_index, dev_index);
 
-       for (res_index = 0; res_index < 10; res_index++) {
-               enum ps3_interrupt_type intr_type;
-               unsigned int interrupt_id;
+int ps3_repository_find_device(struct ps3_repository_device *repo)
+{
+       int result;
+       struct ps3_repository_device tmp = *repo;
+       unsigned int num_dev;
 
-               result = ps3_repository_read_dev_intr(bus_index, dev_index,
-                       res_index, &intr_type, &interrupt_id);
+       BUG_ON(repo->bus_index > 10);
+       BUG_ON(repo->dev_index > 10);
 
-               if (result) {
-                       if (result !=  LV1_NO_ENTRY)
-                               pr_debug("%s:%d ps3_repository_read_dev_intr"
-                                       " (%u:%u) failed\n", __func__, __LINE__,
-                                       bus_index, dev_index);
-                       break;
-               }
+       result = ps3_repository_read_bus_num_dev(tmp.bus_index, &num_dev);
 
-               pr_debug("%s:%d (%u:%u) intr_type %u, interrupt_id %u\n",
-                       __func__, __LINE__, bus_index, dev_index, intr_type,
-                       interrupt_id);
+       if (result) {
+               pr_debug("%s:%d read_bus_num_dev failed\n", __func__, __LINE__);
+               return result;
        }
 
-       for (res_index = 0; res_index < 10; res_index++) {
-               enum ps3_reg_type reg_type;
-               u64 bus_addr;
-               u64 len;
-
-               result = ps3_repository_read_dev_reg(bus_index, dev_index,
-                       res_index, &reg_type, &bus_addr, &len);
-
-               if (result) {
-                       if (result !=  LV1_NO_ENTRY)
-                               pr_debug("%s:%d ps3_repository_read_dev_reg"
-                                       " (%u:%u) failed\n", __func__, __LINE__,
-                                       bus_index, dev_index);
-                       break;
-               }
+       pr_debug("%s:%d: bus_type %u, bus_index %u, bus_id %llu, num_dev %u\n",
+               __func__, __LINE__, tmp.bus_type, tmp.bus_index, tmp.bus_id,
+               num_dev);
 
-               pr_debug("%s:%d (%u:%u) reg_type %u, bus_addr %lxh, len %lxh\n",
-                       __func__, __LINE__, bus_index, dev_index, reg_type,
-                       bus_addr, len);
+       if (tmp.dev_index >= num_dev) {
+               pr_debug("%s:%d: no device found\n", __func__, __LINE__);
+               return -ENODEV;
        }
 
-       pr_debug(" <- %s:%d\n", __func__, __LINE__);
-       return result;
-}
-
-static int dump_stor_dev_info(unsigned int bus_index, unsigned int dev_index)
-{
-       int result = 0;
-       unsigned int num_regions, region_index;
-       u64 port, blk_size, num_blocks;
-
-       pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
-               bus_index, dev_index);
+       result = ps3_repository_read_dev_type(tmp.bus_index, tmp.dev_index,
+               &tmp.dev_type);
 
-       result = ps3_repository_read_stor_dev_info(bus_index, dev_index, &port,
-               &blk_size, &num_blocks, &num_regions);
        if (result) {
-               pr_debug("%s:%d ps3_repository_read_stor_dev_info"
-                       " (%u:%u) failed\n", __func__, __LINE__,
-                       bus_index, dev_index);
-               goto out;
+               pr_debug("%s:%d read_dev_type failed\n", __func__, __LINE__);
+               return result;
        }
 
-       pr_debug("%s:%d  (%u:%u): port %lu, blk_size %lu, num_blocks "
-                "%lu, num_regions %u\n",
-                __func__, __LINE__, bus_index, dev_index, port,
-                blk_size, num_blocks, num_regions);
-
-       for (region_index = 0; region_index < num_regions; region_index++) {
-               unsigned int region_id;
-               u64 region_start, region_size;
-
-               result = ps3_repository_read_stor_dev_region(bus_index,
-                       dev_index, region_index, &region_id, &region_start,
-                       &region_size);
-               if (result) {
-                        pr_debug("%s:%d ps3_repository_read_stor_dev_region"
-                                 " (%u:%u) failed\n", __func__, __LINE__,
-                                 bus_index, dev_index);
-                       break;
-               }
+       result = ps3_repository_read_dev_id(tmp.bus_index, tmp.dev_index,
+               &tmp.dev_id);
 
-               pr_debug("%s:%d (%u:%u) region_id %u, start %lxh, size %lxh\n",
-                        __func__, __LINE__, bus_index, dev_index, region_id,
-                        region_start, region_size);
+       if (result) {
+               pr_debug("%s:%d ps3_repository_read_dev_id failed\n", __func__,
+               __LINE__);
+               return result;
        }
 
-out:
-       pr_debug(" <- %s:%d\n", __func__, __LINE__);
-       return result;
-}
-
-static int dump_device_info(unsigned int bus_index, enum ps3_bus_type bus_type,
-                           unsigned int num_dev)
-{
-       int result = 0;
-       unsigned int dev_index;
-
-       pr_debug(" -> %s:%d: bus_%u\n", __func__, __LINE__, bus_index);
-
-       for (dev_index = 0; dev_index < num_dev; dev_index++) {
-               enum ps3_dev_type dev_type;
-               unsigned int dev_id;
-
-               result = ps3_repository_read_dev_type(bus_index, dev_index,
-                       &dev_type);
-
-               if (result) {
-                       pr_debug("%s:%d ps3_repository_read_dev_type"
-                               " (%u:%u) failed\n", __func__, __LINE__,
-                               bus_index, dev_index);
-                       break;
-               }
-
-               result = ps3_repository_read_dev_id(bus_index, dev_index,
-                       &dev_id);
-
-               if (result) {
-                       pr_debug("%s:%d ps3_repository_read_dev_id"
-                               " (%u:%u) failed\n", __func__, __LINE__,
-                               bus_index, dev_index);
-                       continue;
-               }
-
-               pr_debug("%s:%d  (%u:%u): dev_type %u, dev_id %u\n", __func__,
-                       __LINE__, bus_index, dev_index, dev_type, dev_id);
-
-               ps3_repository_dump_resource_info(bus_index, dev_index);
+       pr_debug("%s:%d: found: dev_type %u, dev_index %u, dev_id %llu\n",
+               __func__, __LINE__, tmp.dev_type, tmp.dev_index, tmp.dev_id);
 
-               if (bus_type == PS3_BUS_TYPE_STORAGE)
-                       dump_stor_dev_info(bus_index, dev_index);
-       }
-
-       pr_debug(" <- %s:%d\n", __func__, __LINE__);
-       return result;
+       *repo = tmp;
+       return 0;
 }
 
-int ps3_repository_dump_bus_info(void)
+int ps3_repository_find_device_by_id(struct ps3_repository_device *repo,
+                                    u64 bus_id, u64 dev_id)
 {
-       int result = 0;
-       unsigned int bus_index;
-
-       pr_debug(" -> %s:%d\n", __func__, __LINE__);
-
-       for (bus_index = 0; bus_index < 10; bus_index++) {
-               enum ps3_bus_type bus_type;
-               unsigned int bus_id;
-               unsigned int num_dev;
-
-               result = ps3_repository_read_bus_type(bus_index, &bus_type);
-
-               if (result) {
-                       pr_debug("%s:%d read_bus_type(%u) failed\n",
-                               __func__, __LINE__, bus_index);
-                       break;
-               }
-
-               result = ps3_repository_read_bus_id(bus_index, &bus_id);
-
-               if (result) {
-                       pr_debug("%s:%d read_bus_id(%u) failed\n",
-                               __func__, __LINE__, bus_index);
-                       continue;
-               }
-
-               if (bus_index != bus_id)
-                       pr_debug("%s:%d bus_index != bus_id\n",
-                               __func__, __LINE__);
+       int result = -ENODEV;
+       struct ps3_repository_device tmp;
+       unsigned int num_dev;
 
-               result = ps3_repository_read_bus_num_dev(bus_index, &num_dev);
+       pr_debug(" -> %s:%u: find device by id %llu:%llu\n", __func__, __LINE__,
+                bus_id, dev_id);
 
+       for (tmp.bus_index = 0; tmp.bus_index < 10; tmp.bus_index++) {
+               result = ps3_repository_read_bus_id(tmp.bus_index,
+                                                   &tmp.bus_id);
                if (result) {
-                       pr_debug("%s:%d read_bus_num_dev(%u) failed\n",
-                               __func__, __LINE__, bus_index);
-                       continue;
+                       pr_debug("%s:%u read_bus_id(%u) failed\n", __func__,
+                                __LINE__, tmp.bus_index);
+                       return result;
                }
 
-               pr_debug("%s:%d bus_%u: bus_type %u, bus_id %u, num_dev %u\n",
-                       __func__, __LINE__, bus_index, bus_type, bus_id,
-                       num_dev);
+               if (tmp.bus_id == bus_id)
+                       goto found_bus;
 
-               dump_device_info(bus_index, bus_type, num_dev);
+               pr_debug("%s:%u: skip, bus_id %llu\n", __func__, __LINE__,
+                        tmp.bus_id);
        }
-
-       pr_debug(" <- %s:%d\n", __func__, __LINE__);
+       pr_debug(" <- %s:%u: bus not found\n", __func__, __LINE__);
        return result;
-}
-#endif /* defined(DEBUG) */
-
-static int find_device(unsigned int bus_index, unsigned int num_dev,
-       unsigned int start_dev_index, enum ps3_dev_type dev_type,
-       struct ps3_repository_device *dev)
-{
-       int result = 0;
-       unsigned int dev_index;
-
-       pr_debug("%s:%d: find dev_type %u\n", __func__, __LINE__, dev_type);
 
-       dev->dev_index = UINT_MAX;
-
-       for (dev_index = start_dev_index; dev_index < num_dev; dev_index++) {
-               enum ps3_dev_type x;
+found_bus:
+       result = ps3_repository_read_bus_type(tmp.bus_index, &tmp.bus_type);
+       if (result) {
+               pr_debug("%s:%u read_bus_type(%u) failed\n", __func__,
+                        __LINE__, tmp.bus_index);
+               return result;
+       }
 
-               result = ps3_repository_read_dev_type(bus_index, dev_index,
-                       &x);
+       result = ps3_repository_read_bus_num_dev(tmp.bus_index, &num_dev);
+       if (result) {
+               pr_debug("%s:%u read_bus_num_dev failed\n", __func__,
+                        __LINE__);
+               return result;
+       }
 
+       for (tmp.dev_index = 0; tmp.dev_index < num_dev; tmp.dev_index++) {
+               result = ps3_repository_read_dev_id(tmp.bus_index,
+                                                   tmp.dev_index,
+                                                   &tmp.dev_id);
                if (result) {
-                       pr_debug("%s:%d read_dev_type failed\n",
-                               __func__, __LINE__);
+                       pr_debug("%s:%u read_dev_id(%u:%u) failed\n", __func__,
+                                __LINE__, tmp.bus_index, tmp.dev_index);
                        return result;
                }
 
-               if (x == dev_type)
-                       break;
-       }
-
-       if (dev_index == num_dev)
-               return -1;
-
-       pr_debug("%s:%d: found dev_type %u at dev_index %u\n",
-               __func__, __LINE__, dev_type, dev_index);
+               if (tmp.dev_id == dev_id)
+                       goto found_dev;
 
-       result = ps3_repository_read_dev_id(bus_index, dev_index,
-               &dev->did.dev_id);
+               pr_debug("%s:%u: skip, dev_id %llu\n", __func__, __LINE__,
+                        tmp.dev_id);
+       }
+       pr_debug(" <- %s:%u: dev not found\n", __func__, __LINE__);
+       return result;
 
+found_dev:
+       result = ps3_repository_read_dev_type(tmp.bus_index, tmp.dev_index,
+                                             &tmp.dev_type);
        if (result) {
-               pr_debug("%s:%d read_dev_id failed\n",
-                       __func__, __LINE__);
+               pr_debug("%s:%u read_dev_type failed\n", __func__, __LINE__);
                return result;
        }
 
-       dev->dev_index = dev_index;
-
-       pr_debug("%s:%d found: dev_id %u\n", __func__, __LINE__,
-               dev->did.dev_id);
-
-       return result;
+       pr_debug(" <- %s:%u: found: type (%u:%u) index (%u:%u) id (%llu:%llu)\n",
+                __func__, __LINE__, tmp.bus_type, tmp.dev_type, tmp.bus_index,
+                tmp.dev_index, tmp.bus_id, tmp.dev_id);
+       *repo = tmp;
+       return 0;
 }
 
-int ps3_repository_find_device (enum ps3_bus_type bus_type,
-       enum ps3_dev_type dev_type,
-       const struct ps3_repository_device *start_dev,
-       struct ps3_repository_device *dev)
+int __devinit ps3_repository_find_devices(enum ps3_bus_type bus_type,
+       int (*callback)(const struct ps3_repository_device *repo))
 {
        int result = 0;
-       unsigned int bus_index;
-       unsigned int num_dev;
-
-       pr_debug("%s:%d: find bus_type %u, dev_type %u\n", __func__, __LINE__,
-               bus_type, dev_type);
-
-       BUG_ON(start_dev && start_dev->bus_index > 10);
-
-       for (bus_index = start_dev ? start_dev->bus_index : 0; bus_index < 10;
-               bus_index++) {
-               enum ps3_bus_type x;
-
-               result = ps3_repository_read_bus_type(bus_index, &x);
-
-               if (result) {
-                       pr_debug("%s:%d read_bus_type failed\n",
-                               __func__, __LINE__);
-                       dev->bus_index = UINT_MAX;
-                       return result;
-               }
-               if (x == bus_type)
-                       break;
-       }
-
-       if (bus_index >= 10)
-               return -ENODEV;
-
-       pr_debug("%s:%d: found bus_type %u at bus_index %u\n",
-               __func__, __LINE__, bus_type, bus_index);
+       struct ps3_repository_device repo;
 
-       result = ps3_repository_read_bus_num_dev(bus_index, &num_dev);
+       pr_debug(" -> %s:%d: find bus_type %u\n", __func__, __LINE__, bus_type);
 
+       repo.bus_type = bus_type;
+       result = ps3_repository_find_bus(repo.bus_type, 0, &repo.bus_index);
        if (result) {
-               pr_debug("%s:%d read_bus_num_dev failed\n",
-                       __func__, __LINE__);
+               pr_debug(" <- %s:%u: bus not found\n", __func__, __LINE__);
                return result;
        }
 
-       result = find_device(bus_index, num_dev, start_dev
-               ? start_dev->dev_index + 1 : 0, dev_type, dev);
-
+       result = ps3_repository_read_bus_id(repo.bus_index, &repo.bus_id);
        if (result) {
-               pr_debug("%s:%d get_did failed\n", __func__, __LINE__);
+               pr_debug("%s:%d read_bus_id(%u) failed\n", __func__, __LINE__,
+                        repo.bus_index);
                return result;
        }
 
-       result = ps3_repository_read_bus_id(bus_index, &dev->did.bus_id);
+       for (repo.dev_index = 0; ; repo.dev_index++) {
+               result = ps3_repository_find_device(&repo);
+               if (result == -ENODEV) {
+                       result = 0;
+                       break;
+               } else if (result)
+                       break;
 
-       if (result) {
-               pr_debug("%s:%d read_bus_id failed\n",
-                       __func__, __LINE__);
-               return result;
+               result = callback(&repo);
+               if (result) {
+                       pr_debug("%s:%d: abort at callback\n", __func__,
+                               __LINE__);
+                       break;
+               }
        }
 
-       dev->bus_index = bus_index;
+       pr_debug(" <- %s:%d\n", __func__, __LINE__);
+       return result;
+}
 
-       pr_debug("%s:%d found: bus_id %u, dev_id %u\n",
-               __func__, __LINE__, dev->did.bus_id, dev->did.dev_id);
+int ps3_repository_find_bus(enum ps3_bus_type bus_type, unsigned int from,
+       unsigned int *bus_index)
+{
+       unsigned int i;
+       enum ps3_bus_type type;
+       int error;
 
-       return result;
+       for (i = from; i < 10; i++) {
+               error = ps3_repository_read_bus_type(i, &type);
+               if (error) {
+                       pr_debug("%s:%d read_bus_type failed\n",
+                               __func__, __LINE__);
+                       *bus_index = UINT_MAX;
+                       return error;
+               }
+               if (type == bus_type) {
+                       *bus_index = i;
+                       return 0;
+               }
+       }
+       *bus_index = UINT_MAX;
+       return -ENODEV;
 }
 
-int ps3_repository_find_interrupt(const struct ps3_repository_device *dev,
+int ps3_repository_find_interrupt(const struct ps3_repository_device *repo,
        enum ps3_interrupt_type intr_type, unsigned int *interrupt_id)
 {
        int result = 0;
@@ -645,8 +517,8 @@ int ps3_repository_find_interrupt(const struct ps3_repository_device *dev,
                enum ps3_interrupt_type t;
                unsigned int id;
 
-               result = ps3_repository_read_dev_intr(dev->bus_index,
-                       dev->dev_index, res_index, &t, &id);
+               result = ps3_repository_read_dev_intr(repo->bus_index,
+                       repo->dev_index, res_index, &t, &id);
 
                if (result) {
                        pr_debug("%s:%d read_dev_intr failed\n",
@@ -669,7 +541,7 @@ int ps3_repository_find_interrupt(const struct ps3_repository_device *dev,
        return result;
 }
 
-int ps3_repository_find_reg(const struct ps3_repository_device *dev,
+int ps3_repository_find_reg(const struct ps3_repository_device *repo,
        enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len)
 {
        int result = 0;
@@ -684,8 +556,8 @@ int ps3_repository_find_reg(const struct ps3_repository_device *dev,
                u64 a;
                u64 l;
 
-               result = ps3_repository_read_dev_reg(dev->bus_index,
-                       dev->dev_index, res_index, &t, &a, &l);
+               result = ps3_repository_read_dev_reg(repo->bus_index,
+                       repo->dev_index, res_index, &t, &a, &l);
 
                if (result) {
                        pr_debug("%s:%d read_dev_reg failed\n",
@@ -716,7 +588,7 @@ int ps3_repository_read_stor_dev_port(unsigned int bus_index,
                make_first_field("bus", bus_index),
                make_field("dev", dev_index),
                make_field("port", 0),
-               0, port, 0);
+               0, port, NULL);
 }
 
 int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index,
@@ -726,7 +598,7 @@ int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index,
                make_first_field("bus", bus_index),
                make_field("dev", dev_index),
                make_field("blk_size", 0),
-               0, blk_size, 0);
+               0, blk_size, NULL);
 }
 
 int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index,
@@ -736,7 +608,7 @@ int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index,
                make_first_field("bus", bus_index),
                make_field("dev", dev_index),
                make_field("n_blocks", 0),
-               0, num_blocks, 0);
+               0, num_blocks, NULL);
 }
 
 int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index,
@@ -749,7 +621,7 @@ int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index,
                make_first_field("bus", bus_index),
                make_field("dev", dev_index),
                make_field("n_regs", 0),
-               0, &v1, 0);
+               0, &v1, NULL);
        *num_regions = v1;
        return result;
 }
@@ -766,7 +638,7 @@ int ps3_repository_read_stor_dev_region_id(unsigned int bus_index,
            make_field("dev", dev_index),
            make_field("region", region_index),
            make_field("id", 0),
-           &v1, 0);
+           &v1, NULL);
        *region_id = v1;
        return result;
 }
@@ -779,7 +651,7 @@ int ps3_repository_read_stor_dev_region_size(unsigned int bus_index,
            make_field("dev", dev_index),
            make_field("region", region_index),
            make_field("size", 0),
-           region_size, 0);
+           region_size, NULL);
 }
 
 int ps3_repository_read_stor_dev_region_start(unsigned int bus_index,
@@ -790,7 +662,7 @@ int ps3_repository_read_stor_dev_region_start(unsigned int bus_index,
            make_field("dev", dev_index),
            make_field("region", region_index),
            make_field("start", 0),
-           region_start, 0);
+           region_start, NULL);
 }
 
 int ps3_repository_read_stor_dev_info(unsigned int bus_index,
@@ -839,6 +711,35 @@ int ps3_repository_read_stor_dev_region(unsigned int bus_index,
        return result;
 }
 
+/**
+ * ps3_repository_read_num_pu - Number of logical PU processors for this lpar.
+ */
+
+int ps3_repository_read_num_pu(u64 *num_pu)
+{
+       *num_pu = 0;
+       return read_node(PS3_LPAR_ID_CURRENT,
+                          make_first_field("bi", 0),
+                          make_field("pun", 0),
+                          0, 0,
+                          num_pu, NULL);
+}
+
+/**
+ * ps3_repository_read_pu_id - Read the logical PU id.
+ * @pu_index: Zero based index.
+ * @pu_id: The logical PU id.
+ */
+
+int ps3_repository_read_pu_id(unsigned int pu_index, u64 *pu_id)
+{
+       return read_node(PS3_LPAR_ID_CURRENT,
+               make_first_field("bi", 0),
+               make_field("pu", pu_index),
+               0, 0,
+               pu_id, NULL);
+}
+
 int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size)
 {
        return read_node(PS3_LPAR_ID_CURRENT,
@@ -846,7 +747,7 @@ int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size)
                make_field("pu", 0),
                ppe_id,
                make_field("rm_size", 0),
-               rm_size, 0);
+               rm_size, NULL);
 }
 
 int ps3_repository_read_region_total(u64 *region_total)
@@ -855,7 +756,7 @@ int ps3_repository_read_region_total(u64 *region_total)
                make_first_field("bi", 0),
                make_field("rgntotal", 0),
                0, 0,
-               region_total, 0);
+               region_total, NULL);
 }
 
 /**
@@ -891,7 +792,7 @@ int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved)
                make_first_field("bi", 0),
                make_field("spun", 0),
                0, 0,
-               &v1, 0);
+               &v1, NULL);
        *num_spu_reserved = v1;
        return result;
 }
@@ -910,7 +811,7 @@ int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id)
                make_first_field("bi", 0),
                make_field("spursvn", 0),
                0, 0,
-               &v1, 0);
+               &v1, NULL);
        *num_resource_id = v1;
        return result;
 }
@@ -923,7 +824,7 @@ int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id)
  */
 
 int ps3_repository_read_spu_resource_id(unsigned int res_index,
-       enum ps3_spu_resource_typeresource_type, unsigned int *resource_id)
+       enum ps3_spu_resource_type *resource_type, unsigned int *resource_id)
 {
        int result;
        u64 v1;
@@ -940,14 +841,14 @@ int ps3_repository_read_spu_resource_id(unsigned int res_index,
        return result;
 }
 
-int ps3_repository_read_boot_dat_address(u64 *address)
+static int ps3_repository_read_boot_dat_address(u64 *address)
 {
        return read_node(PS3_LPAR_ID_CURRENT,
                make_first_field("bi", 0),
                make_field("boot_dat", 0),
                make_field("address", 0),
                0,
-               address, 0);
+               address, NULL);
 }
 
 int ps3_repository_read_boot_dat_size(unsigned int *size)
@@ -960,11 +861,41 @@ int ps3_repository_read_boot_dat_size(unsigned int *size)
                make_field("boot_dat", 0),
                make_field("size", 0),
                0,
-               &v1, 0);
+               &v1, NULL);
        *size = v1;
        return result;
 }
 
+int ps3_repository_read_vuart_av_port(unsigned int *port)
+{
+       int result;
+       u64 v1;
+
+       result = read_node(PS3_LPAR_ID_CURRENT,
+               make_first_field("bi", 0),
+               make_field("vir_uart", 0),
+               make_field("port", 0),
+               make_field("avset", 0),
+               &v1, NULL);
+       *port = v1;
+       return result;
+}
+
+int ps3_repository_read_vuart_sysmgr_port(unsigned int *port)
+{
+       int result;
+       u64 v1;
+
+       result = read_node(PS3_LPAR_ID_CURRENT,
+               make_first_field("bi", 0),
+               make_field("vir_uart", 0),
+               make_field("port", 0),
+               make_field("sysmgr", 0),
+               &v1, NULL);
+       *port = v1;
+       return result;
+}
+
 /**
   * ps3_repository_read_boot_dat_info - Get address and size of cell_ext_os_area.
   * address: lpar address of cell_ext_os_area
@@ -981,6 +912,10 @@ int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size)
                : ps3_repository_read_boot_dat_size(size);
 }
 
+/**
+ * ps3_repository_read_num_be - Number of physical BE processors in the system.
+ */
+
 int ps3_repository_read_num_be(unsigned int *num_be)
 {
        int result;
@@ -991,11 +926,17 @@ int ps3_repository_read_num_be(unsigned int *num_be)
                0,
                0,
                0,
-               &v1, 0);
+               &v1, NULL);
        *num_be = v1;
        return result;
 }
 
+/**
+ * ps3_repository_read_be_node_id - Read the physical BE processor node id.
+ * @be_index: Zero based index.
+ * @node_id: The BE processor node id.
+ */
+
 int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id)
 {
        return read_node(PS3_LPAR_ID_PME,
@@ -1003,7 +944,23 @@ int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id)
                0,
                0,
                0,
-               node_id, 0);
+               node_id, NULL);
+}
+
+/**
+ * ps3_repository_read_be_id - Read the physical BE processor id.
+ * @node_id: The BE processor node id.
+ * @be_id: The BE processor id.
+ */
+
+int ps3_repository_read_be_id(u64 node_id, u64 *be_id)
+{
+       return read_node(PS3_LPAR_ID_PME,
+               make_first_field("be", 0),
+               node_id,
+               0,
+               0,
+               be_id, NULL);
 }
 
 int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq)
@@ -1013,7 +970,7 @@ int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq)
                node_id,
                make_field("clock", 0),
                0,
-               tb_freq, 0);
+               tb_freq, NULL);
 }
 
 int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq)
@@ -1022,7 +979,227 @@ int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq)
        u64 node_id;
 
        *tb_freq = 0;
-       result = ps3_repository_read_be_node_id(0, &node_id);
+       result = ps3_repository_read_be_node_id(be_index, &node_id);
        return result ? result
                : ps3_repository_read_tb_freq(node_id, tb_freq);
 }
+
+int ps3_repository_read_lpm_privileges(unsigned int be_index, u64 *lpar,
+       u64 *rights)
+{
+       int result;
+       u64 node_id;
+
+       *lpar = 0;
+       *rights = 0;
+       result = ps3_repository_read_be_node_id(be_index, &node_id);
+       return result ? result
+               : read_node(PS3_LPAR_ID_PME,
+                           make_first_field("be", 0),
+                           node_id,
+                           make_field("lpm", 0),
+                           make_field("priv", 0),
+                           lpar, rights);
+}
+
+#if defined(DEBUG)
+
+int ps3_repository_dump_resource_info(const struct ps3_repository_device *repo)
+{
+       int result = 0;
+       unsigned int res_index;
+
+       pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
+               repo->bus_index, repo->dev_index);
+
+       for (res_index = 0; res_index < 10; res_index++) {
+               enum ps3_interrupt_type intr_type;
+               unsigned int interrupt_id;
+
+               result = ps3_repository_read_dev_intr(repo->bus_index,
+                       repo->dev_index, res_index, &intr_type, &interrupt_id);
+
+               if (result) {
+                       if (result !=  LV1_NO_ENTRY)
+                               pr_debug("%s:%d ps3_repository_read_dev_intr"
+                                       " (%u:%u) failed\n", __func__, __LINE__,
+                                       repo->bus_index, repo->dev_index);
+                       break;
+               }
+
+               pr_debug("%s:%d (%u:%u) intr_type %u, interrupt_id %u\n",
+                       __func__, __LINE__, repo->bus_index, repo->dev_index,
+                       intr_type, interrupt_id);
+       }
+
+       for (res_index = 0; res_index < 10; res_index++) {
+               enum ps3_reg_type reg_type;
+               u64 bus_addr;
+               u64 len;
+
+               result = ps3_repository_read_dev_reg(repo->bus_index,
+                       repo->dev_index, res_index, &reg_type, &bus_addr, &len);
+
+               if (result) {
+                       if (result !=  LV1_NO_ENTRY)
+                               pr_debug("%s:%d ps3_repository_read_dev_reg"
+                                       " (%u:%u) failed\n", __func__, __LINE__,
+                                       repo->bus_index, repo->dev_index);
+                       break;
+               }
+
+               pr_debug("%s:%d (%u:%u) reg_type %u, bus_addr %lxh, len %lxh\n",
+                       __func__, __LINE__, repo->bus_index, repo->dev_index,
+                       reg_type, bus_addr, len);
+       }
+
+       pr_debug(" <- %s:%d\n", __func__, __LINE__);
+       return result;
+}
+
+static int dump_stor_dev_info(struct ps3_repository_device *repo)
+{
+       int result = 0;
+       unsigned int num_regions, region_index;
+       u64 port, blk_size, num_blocks;
+
+       pr_debug(" -> %s:%d: (%u:%u)\n", __func__, __LINE__,
+               repo->bus_index, repo->dev_index);
+
+       result = ps3_repository_read_stor_dev_info(repo->bus_index,
+               repo->dev_index, &port, &blk_size, &num_blocks, &num_regions);
+       if (result) {
+               pr_debug("%s:%d ps3_repository_read_stor_dev_info"
+                       " (%u:%u) failed\n", __func__, __LINE__,
+                       repo->bus_index, repo->dev_index);
+               goto out;
+       }
+
+       pr_debug("%s:%d  (%u:%u): port %lu, blk_size %lu, num_blocks "
+                "%lu, num_regions %u\n",
+                __func__, __LINE__, repo->bus_index, repo->dev_index, port,
+                blk_size, num_blocks, num_regions);
+
+       for (region_index = 0; region_index < num_regions; region_index++) {
+               unsigned int region_id;
+               u64 region_start, region_size;
+
+               result = ps3_repository_read_stor_dev_region(repo->bus_index,
+                       repo->dev_index, region_index, &region_id,
+                       &region_start, &region_size);
+               if (result) {
+                        pr_debug("%s:%d ps3_repository_read_stor_dev_region"
+                                 " (%u:%u) failed\n", __func__, __LINE__,
+                                 repo->bus_index, repo->dev_index);
+                       break;
+               }
+
+               pr_debug("%s:%d (%u:%u) region_id %u, start %lxh, size %lxh\n",
+                       __func__, __LINE__, repo->bus_index, repo->dev_index,
+                       region_id, region_start, region_size);
+       }
+
+out:
+       pr_debug(" <- %s:%d\n", __func__, __LINE__);
+       return result;
+}
+
+static int dump_device_info(struct ps3_repository_device *repo,
+       unsigned int num_dev)
+{
+       int result = 0;
+
+       pr_debug(" -> %s:%d: bus_%u\n", __func__, __LINE__, repo->bus_index);
+
+       for (repo->dev_index = 0; repo->dev_index < num_dev;
+               repo->dev_index++) {
+
+               result = ps3_repository_read_dev_type(repo->bus_index,
+                       repo->dev_index, &repo->dev_type);
+
+               if (result) {
+                       pr_debug("%s:%d ps3_repository_read_dev_type"
+                               " (%u:%u) failed\n", __func__, __LINE__,
+                               repo->bus_index, repo->dev_index);
+                       break;
+               }
+
+               result = ps3_repository_read_dev_id(repo->bus_index,
+                       repo->dev_index, &repo->dev_id);
+
+               if (result) {
+                       pr_debug("%s:%d ps3_repository_read_dev_id"
+                               " (%u:%u) failed\n", __func__, __LINE__,
+                               repo->bus_index, repo->dev_index);
+                       continue;
+               }
+
+               pr_debug("%s:%d  (%u:%u): dev_type %u, dev_id %lu\n", __func__,
+                       __LINE__, repo->bus_index, repo->dev_index,
+                       repo->dev_type, repo->dev_id);
+
+               ps3_repository_dump_resource_info(repo);
+
+               if (repo->bus_type == PS3_BUS_TYPE_STORAGE)
+                       dump_stor_dev_info(repo);
+       }
+
+       pr_debug(" <- %s:%d\n", __func__, __LINE__);
+       return result;
+}
+
+int ps3_repository_dump_bus_info(void)
+{
+       int result = 0;
+       struct ps3_repository_device repo;
+
+       pr_debug(" -> %s:%d\n", __func__, __LINE__);
+
+       memset(&repo, 0, sizeof(repo));
+
+       for (repo.bus_index = 0; repo.bus_index < 10; repo.bus_index++) {
+               unsigned int num_dev;
+
+               result = ps3_repository_read_bus_type(repo.bus_index,
+                       &repo.bus_type);
+
+               if (result) {
+                       pr_debug("%s:%d read_bus_type(%u) failed\n",
+                               __func__, __LINE__, repo.bus_index);
+                       break;
+               }
+
+               result = ps3_repository_read_bus_id(repo.bus_index,
+                       &repo.bus_id);
+
+               if (result) {
+                       pr_debug("%s:%d read_bus_id(%u) failed\n",
+                               __func__, __LINE__, repo.bus_index);
+                       continue;
+               }
+
+               if (repo.bus_index != repo.bus_id)
+                       pr_debug("%s:%d bus_index != bus_id\n",
+                               __func__, __LINE__);
+
+               result = ps3_repository_read_bus_num_dev(repo.bus_index,
+                       &num_dev);
+
+               if (result) {
+                       pr_debug("%s:%d read_bus_num_dev(%u) failed\n",
+                               __func__, __LINE__, repo.bus_index);
+                       continue;
+               }
+
+               pr_debug("%s:%d bus_%u: bus_type %u, bus_id %lu, num_dev %u\n",
+                       __func__, __LINE__, repo.bus_index, repo.bus_type,
+                       repo.bus_id, num_dev);
+
+               dump_device_info(&repo, num_dev);
+       }
+
+       pr_debug(" <- %s:%d\n", __func__, __LINE__);
+       return result;
+}
+
+#endif /* defined(DEBUG) */