include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / arch / powerpc / platforms / ps3 / mm.c
index 5b3fb2b..7925751 100644 (file)
@@ -22,7 +22,9 @@
 #include <linux/module.h>
 #include <linux/memory_hotplug.h>
 #include <linux/lmb.h>
+#include <linux/slab.h>
 
+#include <asm/cell-regs.h>
 #include <asm/firmware.h>
 #include <asm/prom.h>
 #include <asm/udbg.h>
@@ -33,7 +35,7 @@
 #if defined(DEBUG)
 #define DBG udbg_printf
 #else
-#define DBG pr_debug
+#define DBG pr_devel
 #endif
 
 enum {
@@ -79,8 +81,8 @@ enum {
  */
 
 struct mem_region {
-       unsigned long base;
-       unsigned long size;
+       u64 base;
+       u64 size;
        unsigned long offset;
 };
 
@@ -103,9 +105,9 @@ struct mem_region {
  */
 
 struct map {
-       unsigned long total;
-       unsigned long vas_id;
-       unsigned long htab_size;
+       u64 total;
+       u64 vas_id;
+       u64 htab_size;
        struct mem_region rm;
        struct mem_region r1;
 };
@@ -114,13 +116,13 @@ struct map {
 static void __maybe_unused _debug_dump_map(const struct map *m,
        const char *func, int line)
 {
-       DBG("%s:%d: map.total     = %lxh\n", func, line, m->total);
-       DBG("%s:%d: map.rm.size   = %lxh\n", func, line, m->rm.size);
-       DBG("%s:%d: map.vas_id    = %lu\n", func, line, m->vas_id);
-       DBG("%s:%d: map.htab_size = %lxh\n", func, line, m->htab_size);
-       DBG("%s:%d: map.r1.base   = %lxh\n", func, line, m->r1.base);
+       DBG("%s:%d: map.total     = %llxh\n", func, line, m->total);
+       DBG("%s:%d: map.rm.size   = %llxh\n", func, line, m->rm.size);
+       DBG("%s:%d: map.vas_id    = %llu\n", func, line, m->vas_id);
+       DBG("%s:%d: map.htab_size = %llxh\n", func, line, m->htab_size);
+       DBG("%s:%d: map.r1.base   = %llxh\n", func, line, m->r1.base);
        DBG("%s:%d: map.r1.offset = %lxh\n", func, line, m->r1.offset);
-       DBG("%s:%d: map.r1.size   = %lxh\n", func, line, m->r1.size);
+       DBG("%s:%d: map.r1.size   = %llxh\n", func, line, m->r1.size);
 }
 
 static struct map map;
@@ -146,11 +148,11 @@ EXPORT_SYMBOL(ps3_mm_phys_to_lpar);
 void __init ps3_mm_vas_create(unsigned long* htab_size)
 {
        int result;
-       unsigned long start_address;
-       unsigned long size;
-       unsigned long access_right;
-       unsigned long max_page_size;
-       unsigned long flags;
+       u64 start_address;
+       u64 size;
+       u64 access_right;
+       u64 max_page_size;
+       u64 flags;
 
        result = lv1_query_logical_partition_address_region_info(0,
                &start_address, &size, &access_right, &max_page_size,
@@ -164,7 +166,7 @@ void __init ps3_mm_vas_create(unsigned long* htab_size)
        }
 
        if (max_page_size < PAGE_SHIFT_16M) {
-               DBG("%s:%d: bad max_page_size %lxh\n", __func__, __LINE__,
+               DBG("%s:%d: bad max_page_size %llxh\n", __func__, __LINE__,
                        max_page_size);
                goto fail;
        }
@@ -208,7 +210,7 @@ void ps3_mm_vas_destroy(void)
 {
        int result;
 
-       DBG("%s:%d: map.vas_id    = %lu\n", __func__, __LINE__, map.vas_id);
+       DBG("%s:%d: map.vas_id    = %llu\n", __func__, __LINE__, map.vas_id);
 
        if (map.vas_id) {
                result = lv1_select_virtual_address_space(0);
@@ -235,15 +237,14 @@ void ps3_mm_vas_destroy(void)
 static int ps3_mm_region_create(struct mem_region *r, unsigned long size)
 {
        int result;
-       unsigned long muid;
+       u64 muid;
 
        r->size = _ALIGN_DOWN(size, 1 << PAGE_SHIFT_16M);
 
        DBG("%s:%d requested  %lxh\n", __func__, __LINE__, size);
-       DBG("%s:%d actual     %lxh\n", __func__, __LINE__, r->size);
-       DBG("%s:%d difference %lxh (%luMB)\n", __func__, __LINE__,
-               (unsigned long)(size - r->size),
-               (size - r->size) / 1024 / 1024);
+       DBG("%s:%d actual     %llxh\n", __func__, __LINE__, r->size);
+       DBG("%s:%d difference %llxh (%lluMB)\n", __func__, __LINE__,
+               size - r->size, (size - r->size) / 1024 / 1024);
 
        if (r->size == 0) {
                DBG("%s:%d: size == 0\n", __func__, __LINE__);
@@ -277,7 +278,7 @@ static void ps3_mm_region_destroy(struct mem_region *r)
 {
        int result;
 
-       DBG("%s:%d: r->base = %lxh\n", __func__, __LINE__, r->base);
+       DBG("%s:%d: r->base = %llxh\n", __func__, __LINE__, r->base);
        if (r->base) {
                result = lv1_release_memory(r->base);
                BUG_ON(result);
@@ -312,21 +313,24 @@ static int __init ps3_mm_add_memory(void)
        result = add_memory(0, start_addr, map.r1.size);
 
        if (result) {
-               DBG("%s:%d: add_memory failed: (%d)\n",
+               pr_err("%s:%d: add_memory failed: (%d)\n",
                        __func__, __LINE__, result);
                return result;
        }
 
+       lmb_add(start_addr, map.r1.size);
+       lmb_analyze();
+
        result = online_pages(start_pfn, nr_pages);
 
        if (result)
-               DBG("%s:%d: online_pages failed: (%d)\n",
+               pr_err("%s:%d: online_pages failed: (%d)\n",
                        __func__, __LINE__, result);
 
        return result;
 }
 
-core_initcall(ps3_mm_add_memory);
+device_initcall(ps3_mm_add_memory);
 
 /*============================================================================*/
 /* dma routines                                                               */
@@ -352,7 +356,7 @@ static unsigned long dma_sb_lpar_to_bus(struct ps3_dma_region *r,
 static void  __maybe_unused _dma_dump_region(const struct ps3_dma_region *r,
        const char *func, int line)
 {
-       DBG("%s:%d: dev        %lu:%lu\n", func, line, r->dev->bus_id,
+       DBG("%s:%d: dev        %llu:%llu\n", func, line, r->dev->bus_id,
                r->dev->dev_id);
        DBG("%s:%d: page_size  %u\n", func, line, r->page_size);
        DBG("%s:%d: bus_addr   %lxh\n", func, line, r->bus_addr);
@@ -387,7 +391,7 @@ struct dma_chunk {
 static void _dma_dump_chunk (const struct dma_chunk* c, const char* func,
        int line)
 {
-       DBG("%s:%d: r.dev        %lu:%lu\n", func, line,
+       DBG("%s:%d: r.dev        %llu:%llu\n", func, line,
                c->region->dev->bus_id, c->region->dev->dev_id);
        DBG("%s:%d: r.bus_addr   %lxh\n", func, line, c->region->bus_addr);
        DBG("%s:%d: r.page_size  %u\n", func, line, c->region->page_size);
@@ -593,7 +597,7 @@ static int dma_ioc0_map_pages(struct ps3_dma_region *r, unsigned long phys_addr,
 
        /* build ioptes for the area */
        pages = len >> r->page_size;
-       DBG("%s: pgsize=%#x len=%#lx pages=%#x iopteflag=%#lx\n", __func__,
+       DBG("%s: pgsize=%#x len=%#lx pages=%#x iopteflag=%#llx\n", __func__,
            r->page_size, r->len, pages, iopte_flag);
        for (iopage = 0; iopage < pages; iopage++) {
                offset = (1 << r->page_size) * iopage;
@@ -603,9 +607,8 @@ static int dma_ioc0_map_pages(struct ps3_dma_region *r, unsigned long phys_addr,
                                       r->ioid,
                                       iopte_flag);
                if (result) {
-                       printk(KERN_WARNING "%s:%d: lv1_map_device_dma_region "
-                               "failed: %s\n", __func__, __LINE__,
-                               ps3_result(result));
+                       pr_warning("%s:%d: lv1_put_iopte failed: %s\n",
+                                  __func__, __LINE__, ps3_result(result));
                        goto fail_map;
                }
                DBG("%s: pg=%d bus=%#lx, lpar=%#lx, ioid=%#x\n", __func__,
@@ -645,13 +648,14 @@ fail_alloc:
 static int dma_sb_region_create(struct ps3_dma_region *r)
 {
        int result;
+       u64 bus_addr;
 
-       pr_info(" -> %s:%d:\n", __func__, __LINE__);
+       DBG(" -> %s:%d:\n", __func__, __LINE__);
 
        BUG_ON(!r);
 
        if (!r->dev->bus_id) {
-               pr_info("%s:%d: %lu:%lu no dma\n", __func__, __LINE__,
+               pr_info("%s:%d: %llu:%llu no dma\n", __func__, __LINE__,
                        r->dev->bus_id, r->dev->dev_id);
                return 0;
        }
@@ -668,7 +672,8 @@ static int dma_sb_region_create(struct ps3_dma_region *r)
 
        result = lv1_allocate_device_dma_region(r->dev->bus_id, r->dev->dev_id,
                roundup_pow_of_two(r->len), r->page_size, r->region_type,
-               &r->bus_addr);
+               &bus_addr);
+       r->bus_addr = bus_addr;
 
        if (result) {
                DBG("%s:%d: lv1_allocate_device_dma_region failed: %s\n",
@@ -682,6 +687,7 @@ static int dma_sb_region_create(struct ps3_dma_region *r)
 static int dma_ioc0_region_create(struct ps3_dma_region *r)
 {
        int result;
+       u64 bus_addr;
 
        INIT_LIST_HEAD(&r->chunk_list.head);
        spin_lock_init(&r->chunk_list.lock);
@@ -689,7 +695,8 @@ static int dma_ioc0_region_create(struct ps3_dma_region *r)
        result = lv1_allocate_io_segment(0,
                                         r->len,
                                         r->page_size,
-                                        &r->bus_addr);
+                                        &bus_addr);
+       r->bus_addr = bus_addr;
        if (result) {
                DBG("%s:%d: lv1_allocate_io_segment failed: %s\n",
                        __func__, __LINE__, ps3_result(result));
@@ -717,7 +724,7 @@ static int dma_sb_region_free(struct ps3_dma_region *r)
        BUG_ON(!r);
 
        if (!r->dev->bus_id) {
-               pr_info("%s:%d: %lu:%lu no dma\n", __func__, __LINE__,
+               pr_info("%s:%d: %llu:%llu no dma\n", __func__, __LINE__,
                        r->dev->bus_id, r->dev->dev_id);
                return 0;
        }
@@ -774,7 +781,7 @@ static int dma_ioc0_region_free(struct ps3_dma_region *r)
  */
 
 static int dma_sb_map_area(struct ps3_dma_region *r, unsigned long virt_addr,
-          unsigned long len, unsigned long *bus_addr,
+          unsigned long len, dma_addr_t *bus_addr,
           u64 iopte_flag)
 {
        int result;
@@ -797,7 +804,7 @@ static int dma_sb_map_area(struct ps3_dma_region *r, unsigned long virt_addr,
                DBG("%s:%d lpar_addr %lxh\n", __func__, __LINE__,
                        lpar_addr);
                DBG("%s:%d len       %lxh\n", __func__, __LINE__, len);
-               DBG("%s:%d bus_addr  %lxh (%lxh)\n", __func__, __LINE__,
+               DBG("%s:%d bus_addr  %llxh (%lxh)\n", __func__, __LINE__,
                *bus_addr, len);
        }
 
@@ -829,7 +836,7 @@ static int dma_sb_map_area(struct ps3_dma_region *r, unsigned long virt_addr,
 }
 
 static int dma_ioc0_map_area(struct ps3_dma_region *r, unsigned long virt_addr,
-            unsigned long len, unsigned long *bus_addr,
+            unsigned long len, dma_addr_t *bus_addr,
             u64 iopte_flag)
 {
        int result;
@@ -869,7 +876,7 @@ static int dma_ioc0_map_area(struct ps3_dma_region *r, unsigned long virt_addr,
                return result;
        }
        *bus_addr = c->bus_addr + phys_addr - aligned_phys;
-       DBG("%s: va=%#lx pa=%#lx a_pa=%#lx bus=%#lx\n", __func__,
+       DBG("%s: va=%#lx pa=%#lx a_pa=%#lx bus=%#llx\n", __func__,
            virt_addr, phys_addr, aligned_phys, *bus_addr);
        c->usage_count = 1;
 
@@ -886,7 +893,7 @@ static int dma_ioc0_map_area(struct ps3_dma_region *r, unsigned long virt_addr,
  * This is the common dma unmap routine.
  */
 
-static int dma_sb_unmap_area(struct ps3_dma_region *r, unsigned long bus_addr,
+static int dma_sb_unmap_area(struct ps3_dma_region *r, dma_addr_t bus_addr,
        unsigned long len)
 {
        unsigned long flags;
@@ -900,7 +907,7 @@ static int dma_sb_unmap_area(struct ps3_dma_region *r, unsigned long bus_addr,
                        1 << r->page_size);
                unsigned long aligned_len = _ALIGN_UP(len + bus_addr
                        - aligned_bus, 1 << r->page_size);
-               DBG("%s:%d: not found: bus_addr %lxh\n",
+               DBG("%s:%d: not found: bus_addr %llxh\n",
                        __func__, __LINE__, bus_addr);
                DBG("%s:%d: not found: len %lxh\n",
                        __func__, __LINE__, len);
@@ -923,12 +930,12 @@ static int dma_sb_unmap_area(struct ps3_dma_region *r, unsigned long bus_addr,
 }
 
 static int dma_ioc0_unmap_area(struct ps3_dma_region *r,
-                       unsigned long bus_addr, unsigned long len)
+                       dma_addr_t bus_addr, unsigned long len)
 {
        unsigned long flags;
        struct dma_chunk *c;
 
-       DBG("%s: start a=%#lx l=%#lx\n", __func__, bus_addr, len);
+       DBG("%s: start a=%#llx l=%#lx\n", __func__, bus_addr, len);
        spin_lock_irqsave(&r->chunk_list.lock, flags);
        c = dma_find_chunk(r, bus_addr, len);
 
@@ -938,7 +945,7 @@ static int dma_ioc0_unmap_area(struct ps3_dma_region *r,
                unsigned long aligned_len = _ALIGN_UP(len + bus_addr
                                                      - aligned_bus,
                                                      1 << r->page_size);
-               DBG("%s:%d: not found: bus_addr %lxh\n",
+               DBG("%s:%d: not found: bus_addr %llxh\n",
                    __func__, __LINE__, bus_addr);
                DBG("%s:%d: not found: len %lxh\n",
                    __func__, __LINE__, len);
@@ -972,7 +979,8 @@ static int dma_ioc0_unmap_area(struct ps3_dma_region *r,
 static int dma_sb_region_create_linear(struct ps3_dma_region *r)
 {
        int result;
-       unsigned long virt_addr, len, tmp;
+       unsigned long virt_addr, len;
+       dma_addr_t tmp;
 
        if (r->len > 16*1024*1024) {    /* FIXME: need proper fix */
                /* force 16M dma pages for linear mapping */
@@ -994,7 +1002,8 @@ static int dma_sb_region_create_linear(struct ps3_dma_region *r)
                if (len > r->len)
                        len = r->len;
                result = dma_sb_map_area(r, virt_addr, len, &tmp,
-                       IOPTE_PP_W | IOPTE_PP_R | IOPTE_SO_RW | IOPTE_M);
+                       CBE_IOPTE_PP_W | CBE_IOPTE_PP_R | CBE_IOPTE_SO_RW |
+                       CBE_IOPTE_M);
                BUG_ON(result);
        }
 
@@ -1007,7 +1016,8 @@ static int dma_sb_region_create_linear(struct ps3_dma_region *r)
                else
                        len -= map.rm.size - r->offset;
                result = dma_sb_map_area(r, virt_addr, len, &tmp,
-                       IOPTE_PP_W | IOPTE_PP_R | IOPTE_SO_RW | IOPTE_M);
+                       CBE_IOPTE_PP_W | CBE_IOPTE_PP_R | CBE_IOPTE_SO_RW |
+                       CBE_IOPTE_M);
                BUG_ON(result);
        }
 
@@ -1024,7 +1034,8 @@ static int dma_sb_region_create_linear(struct ps3_dma_region *r)
 static int dma_sb_region_free_linear(struct ps3_dma_region *r)
 {
        int result;
-       unsigned long bus_addr, len, lpar_addr;
+       dma_addr_t bus_addr;
+       unsigned long len, lpar_addr;
 
        if (r->offset < map.rm.size) {
                /* Unmap (part of) 1st RAM chunk */
@@ -1069,7 +1080,7 @@ static int dma_sb_region_free_linear(struct ps3_dma_region *r)
  */
 
 static int dma_sb_map_area_linear(struct ps3_dma_region *r,
-       unsigned long virt_addr, unsigned long len, unsigned long *bus_addr,
+       unsigned long virt_addr, unsigned long len, dma_addr_t *bus_addr,
        u64 iopte_flag)
 {
        unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr)
@@ -1088,7 +1099,7 @@ static int dma_sb_map_area_linear(struct ps3_dma_region *r,
  */
 
 static int dma_sb_unmap_area_linear(struct ps3_dma_region *r,
-       unsigned long bus_addr, unsigned long len)
+       dma_addr_t bus_addr, unsigned long len)
 {
        return 0;
 };
@@ -1166,13 +1177,13 @@ int ps3_dma_region_free(struct ps3_dma_region *r)
 EXPORT_SYMBOL(ps3_dma_region_free);
 
 int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr,
-       unsigned long len, unsigned long *bus_addr,
+       unsigned long len, dma_addr_t *bus_addr,
        u64 iopte_flag)
 {
        return r->region_ops->map(r, virt_addr, len, bus_addr, iopte_flag);
 }
 
-int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long bus_addr,
+int ps3_dma_unmap(struct ps3_dma_region *r, dma_addr_t bus_addr,
        unsigned long len)
 {
        return r->region_ops->unmap(r, bus_addr, len);