- Update to 2.6.25-rc3.
[linux-flexiantxendom0-3.2.10.git] / arch / powerpc / platforms / ps3 / repository.c
index 8baf050..22063ad 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 char* func, int line)
+static void _dump_field(const char *hdr, u64 n, const char *func, int line)
 {
 #if defined(DEBUG)
        char s[16];
@@ -50,8 +50,8 @@ static void _dump_field(const char *hdr, u64 n, const char* func, int line)
 
 #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 char* func, 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,7 +63,7 @@ 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 char* func, 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);
@@ -165,7 +165,7 @@ 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, u64 *bus_id)
@@ -190,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;
 }
@@ -205,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;
 }
@@ -218,7 +218,7 @@ 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,
@@ -231,7 +231,7 @@ int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index,
                make_field("dev", dev_index),
                make_field("id", 0),
                0,
-               dev_id, 0);
+               dev_id, NULL);
        return result;
 }
 
@@ -246,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 int* interrupt_id)
+       enum ps3_interrupt_type *intr_type, unsigned int *interrupt_id)
 {
        int result;
        u64 v1;
@@ -282,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;
 }
@@ -344,35 +344,6 @@ int ps3_repository_find_device(struct ps3_repository_device *repo)
                return result;
        }
 
-       if (tmp.bus_type == PS3_BUS_TYPE_STORAGE) {
-               /*
-                * A storage device may show up in the repository before the
-                * hypervisor has finished probing its type and regions
-                */
-               unsigned int num_regions;
-
-               if (tmp.dev_type == PS3_DEV_TYPE_STOR_DUMMY) {
-                       pr_debug("%s:%u storage device not ready\n", __func__,
-                                __LINE__);
-                       return -ENODEV;
-               }
-
-               result = ps3_repository_read_stor_dev_num_regions(tmp.bus_index,
-                                                                 tmp.dev_index,
-                                                                 &num_regions);
-               if (result) {
-                       pr_debug("%s:%d read_stor_dev_num_regions failed\n",
-                                __func__, __LINE__);
-                       return result;
-               }
-
-               if (!num_regions) {
-                       pr_debug("%s:%u storage device has no regions yet\n",
-                                __func__, __LINE__);
-                       return -ENODEV;
-               }
-       }
-
        result = ps3_repository_read_dev_id(tmp.bus_index, tmp.dev_index,
                &tmp.dev_id);
 
@@ -389,58 +360,119 @@ int ps3_repository_find_device(struct ps3_repository_device *repo)
        return 0;
 }
 
-int __devinit ps3_repository_find_devices(enum ps3_bus_type bus_type,
-       int (*callback)(const struct ps3_repository_device *repo))
+int ps3_repository_find_device_by_id(struct ps3_repository_device *repo,
+                                    u64 bus_id, u64 dev_id)
 {
-       int result = 0;
-       struct ps3_repository_device repo;
-
-       pr_debug(" -> %s:%d: find bus_type %u\n", __func__, __LINE__, bus_type);
+       int result = -ENODEV;
+       struct ps3_repository_device tmp;
+       unsigned int num_dev;
 
-       for (repo.bus_index = 0; repo.bus_index < 10; repo.bus_index++) {
-
-               result = ps3_repository_read_bus_type(repo.bus_index,
-                       &repo.bus_type);
+       pr_debug(" -> %s:%u: find device by id %lu:%lu\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_type(%u) failed\n",
-                               __func__, __LINE__, repo.bus_index);
-                       break;
+                       pr_debug("%s:%u read_bus_id(%u) failed\n", __func__,
+                                __LINE__, tmp.bus_index);
+                       return result;
                }
 
-               if (repo.bus_type != bus_type) {
-                       pr_debug("%s:%d: skip, bus_type %u\n", __func__,
-                               __LINE__, repo.bus_type);
-                       continue;
-               }
+               if (tmp.bus_id == bus_id)
+                       goto found_bus;
 
-               result = ps3_repository_read_bus_id(repo.bus_index,
-                       &repo.bus_id);
+               pr_debug("%s:%u: skip, bus_id %lu\n", __func__, __LINE__,
+                        tmp.bus_id);
+       }
+       pr_debug(" <- %s:%u: bus not found\n", __func__, __LINE__);
+       return result;
+
+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_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_bus_id(%u) failed\n",
-                               __func__, __LINE__, repo.bus_index);
-                       continue;
+                       pr_debug("%s:%u read_dev_id(%u:%u) failed\n", __func__,
+                                __LINE__, tmp.bus_index, tmp.dev_index);
+                       return result;
                }
 
-               for (repo.dev_index = 0; ; repo.dev_index++) {
-                       result = ps3_repository_find_device(&repo);
+               if (tmp.dev_id == dev_id)
+                       goto found_dev;
+
+               pr_debug("%s:%u: skip, dev_id %lu\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:%u read_dev_type failed\n", __func__, __LINE__);
+               return result;
+       }
+
+       pr_debug(" <- %s:%u: found: type (%u:%u) index (%u:%u) id (%lu:%lu)\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 __devinit ps3_repository_find_devices(enum ps3_bus_type bus_type,
+       int (*callback)(const struct ps3_repository_device *repo))
+{
+       int result = 0;
+       struct ps3_repository_device repo;
+
+       pr_debug(" -> %s:%d: find bus_type %u\n", __func__, __LINE__, bus_type);
 
-                       if (result == -ENODEV) {
-                               result = 0;
-                               break;
-                       } else if (result)
-                               break;
+       repo.bus_type = bus_type;
+       result = ps3_repository_find_bus(repo.bus_type, 0, &repo.bus_index);
+       if (result) {
+               pr_debug(" <- %s:%u: bus not found\n", __func__, __LINE__);
+               return result;
+       }
 
-                       result = callback(&repo);
+       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);
+               return result;
+       }
+
+       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: abort at callback\n", __func__,
-                                       __LINE__);
-                               break;
-                       }
+               result = callback(&repo);
+               if (result) {
+                       pr_debug("%s:%d: abort at callback\n", __func__,
+                               __LINE__);
+                       break;
                }
-               break;
        }
 
        pr_debug(" <- %s:%d\n", __func__, __LINE__);
@@ -556,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,
@@ -566,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,
@@ -576,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,
@@ -589,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;
 }
@@ -606,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;
 }
@@ -619,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,
@@ -630,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,
@@ -679,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,
@@ -686,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)
@@ -695,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);
 }
 
 /**
@@ -731,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;
 }
@@ -750,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;
 }
@@ -763,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_type* resource_type, unsigned int *resource_id)
+       enum ps3_spu_resource_type *resource_type, unsigned int *resource_id)
 {
        int result;
        u64 v1;
@@ -780,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)
@@ -800,7 +861,7 @@ 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;
 }
@@ -815,7 +876,7 @@ int ps3_repository_read_vuart_av_port(unsigned int *port)
                make_field("vir_uart", 0),
                make_field("port", 0),
                make_field("avset", 0),
-               &v1, 0);
+               &v1, NULL);
        *port = v1;
        return result;
 }
@@ -830,7 +891,7 @@ int ps3_repository_read_vuart_sysmgr_port(unsigned int *port)
                make_field("vir_uart", 0),
                make_field("port", 0),
                make_field("sysmgr", 0),
-               &v1, 0);
+               &v1, NULL);
        *port = v1;
        return result;
 }
@@ -851,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;
@@ -861,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,
@@ -873,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)
@@ -883,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)
@@ -892,11 +979,29 @@ 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)