RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / arch / powerpc / platforms / ps3 / mm.c
blobf8a3e206c584b42f97b811da0b09b1402633bb95
1 /*
2 * PS3 address space management.
4 * Copyright (C) 2006 Sony Computer Entertainment Inc.
5 * Copyright 2006 Sony Corp.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/memory_hotplug.h>
25 #include <asm/firmware.h>
26 #include <asm/lmb.h>
27 #include <asm/udbg.h>
28 #include <asm/lv1call.h>
30 #include "platform.h"
32 #if defined(DEBUG)
33 #define DBG(fmt...) udbg_printf(fmt)
34 #else
35 #define DBG(fmt...) do{if(0)printk(fmt);}while(0)
36 #endif
38 enum {
39 #if defined(CONFIG_PS3_USE_LPAR_ADDR)
40 USE_LPAR_ADDR = 1,
41 #else
42 USE_LPAR_ADDR = 0,
43 #endif
44 #if defined(CONFIG_PS3_DYNAMIC_DMA)
45 USE_DYNAMIC_DMA = 1,
46 #else
47 USE_DYNAMIC_DMA = 0,
48 #endif
51 enum {
52 PAGE_SHIFT_4K = 12U,
53 PAGE_SHIFT_64K = 16U,
54 PAGE_SHIFT_16M = 24U,
57 static unsigned long make_page_sizes(unsigned long a, unsigned long b)
59 return (a << 56) | (b << 48);
62 enum {
63 ALLOCATE_MEMORY_TRY_ALT_UNIT = 0X04,
64 ALLOCATE_MEMORY_ADDR_ZERO = 0X08,
67 /* valid htab sizes are {18,19,20} = 256K, 512K, 1M */
69 enum {
70 HTAB_SIZE_MAX = 20U, /* HV limit of 1MB */
71 HTAB_SIZE_MIN = 18U, /* CPU limit of 256KB */
74 /*============================================================================*/
75 /* virtual address space routines */
76 /*============================================================================*/
78 /**
79 * struct mem_region - memory region structure
80 * @base: base address
81 * @size: size in bytes
82 * @offset: difference between base and rm.size
85 struct mem_region {
86 unsigned long base;
87 unsigned long size;
88 unsigned long offset;
91 /**
92 * struct map - address space state variables holder
93 * @total: total memory available as reported by HV
94 * @vas_id - HV virtual address space id
95 * @htab_size: htab size in bytes
97 * The HV virtual address space (vas) allows for hotplug memory regions.
98 * Memory regions can be created and destroyed in the vas at runtime.
99 * @rm: real mode (bootmem) region
100 * @r1: hotplug memory region(s)
102 * ps3 addresses
103 * virt_addr: a cpu 'translated' effective address
104 * phys_addr: an address in what Linux thinks is the physical address space
105 * lpar_addr: an address in the HV virtual address space
106 * bus_addr: an io controller 'translated' address on a device bus
109 struct map {
110 unsigned long total;
111 unsigned long vas_id;
112 unsigned long htab_size;
113 struct mem_region rm;
114 struct mem_region r1;
117 #define debug_dump_map(x) _debug_dump_map(x, __func__, __LINE__)
118 static void _debug_dump_map(const struct map* m, const char* func, int line)
120 DBG("%s:%d: map.total = %lxh\n", func, line, m->total);
121 DBG("%s:%d: map.rm.size = %lxh\n", func, line, m->rm.size);
122 DBG("%s:%d: map.vas_id = %lu\n", func, line, m->vas_id);
123 DBG("%s:%d: map.htab_size = %lxh\n", func, line, m->htab_size);
124 DBG("%s:%d: map.r1.base = %lxh\n", func, line, m->r1.base);
125 DBG("%s:%d: map.r1.offset = %lxh\n", func, line, m->r1.offset);
126 DBG("%s:%d: map.r1.size = %lxh\n", func, line, m->r1.size);
129 static struct map map;
132 * ps3_mm_phys_to_lpar - translate a linux physical address to lpar address
133 * @phys_addr: linux physical address
136 unsigned long ps3_mm_phys_to_lpar(unsigned long phys_addr)
138 BUG_ON(is_kernel_addr(phys_addr));
139 if (USE_LPAR_ADDR)
140 return phys_addr;
141 else
142 return (phys_addr < map.rm.size || phys_addr >= map.total)
143 ? phys_addr : phys_addr + map.r1.offset;
146 EXPORT_SYMBOL(ps3_mm_phys_to_lpar);
149 * ps3_mm_vas_create - create the virtual address space
152 void __init ps3_mm_vas_create(unsigned long* htab_size)
154 int result;
155 unsigned long start_address;
156 unsigned long size;
157 unsigned long access_right;
158 unsigned long max_page_size;
159 unsigned long flags;
161 result = lv1_query_logical_partition_address_region_info(0,
162 &start_address, &size, &access_right, &max_page_size,
163 &flags);
165 if (result) {
166 DBG("%s:%d: lv1_query_logical_partition_address_region_info "
167 "failed: %s\n", __func__, __LINE__,
168 ps3_result(result));
169 goto fail;
172 if (max_page_size < PAGE_SHIFT_16M) {
173 DBG("%s:%d: bad max_page_size %lxh\n", __func__, __LINE__,
174 max_page_size);
175 goto fail;
178 BUILD_BUG_ON(CONFIG_PS3_HTAB_SIZE > HTAB_SIZE_MAX);
179 BUILD_BUG_ON(CONFIG_PS3_HTAB_SIZE < HTAB_SIZE_MIN);
181 result = lv1_construct_virtual_address_space(CONFIG_PS3_HTAB_SIZE,
182 2, make_page_sizes(PAGE_SHIFT_16M, PAGE_SHIFT_64K),
183 &map.vas_id, &map.htab_size);
185 if (result) {
186 DBG("%s:%d: lv1_construct_virtual_address_space failed: %s\n",
187 __func__, __LINE__, ps3_result(result));
188 goto fail;
191 result = lv1_select_virtual_address_space(map.vas_id);
193 if (result) {
194 DBG("%s:%d: lv1_select_virtual_address_space failed: %s\n",
195 __func__, __LINE__, ps3_result(result));
196 goto fail;
199 *htab_size = map.htab_size;
201 debug_dump_map(&map);
203 return;
205 fail:
206 panic("ps3_mm_vas_create failed");
210 * ps3_mm_vas_destroy -
213 void ps3_mm_vas_destroy(void)
215 if (map.vas_id) {
216 lv1_select_virtual_address_space(0);
217 lv1_destruct_virtual_address_space(map.vas_id);
218 map.vas_id = 0;
222 /*============================================================================*/
223 /* memory hotplug routines */
224 /*============================================================================*/
227 * ps3_mm_region_create - create a memory region in the vas
228 * @r: pointer to a struct mem_region to accept initialized values
229 * @size: requested region size
231 * This implementation creates the region with the vas large page size.
232 * @size is rounded down to a multiple of the vas large page size.
235 int ps3_mm_region_create(struct mem_region *r, unsigned long size)
237 int result;
238 unsigned long muid;
240 r->size = _ALIGN_DOWN(size, 1 << PAGE_SHIFT_16M);
242 DBG("%s:%d requested %lxh\n", __func__, __LINE__, size);
243 DBG("%s:%d actual %lxh\n", __func__, __LINE__, r->size);
244 DBG("%s:%d difference %lxh (%luMB)\n", __func__, __LINE__,
245 (unsigned long)(size - r->size),
246 (size - r->size) / 1024 / 1024);
248 if (r->size == 0) {
249 DBG("%s:%d: size == 0\n", __func__, __LINE__);
250 result = -1;
251 goto zero_region;
254 result = lv1_allocate_memory(r->size, PAGE_SHIFT_16M, 0,
255 ALLOCATE_MEMORY_TRY_ALT_UNIT, &r->base, &muid);
257 if (result || r->base < map.rm.size) {
258 DBG("%s:%d: lv1_allocate_memory failed: %s\n",
259 __func__, __LINE__, ps3_result(result));
260 goto zero_region;
263 r->offset = r->base - map.rm.size;
264 return result;
266 zero_region:
267 r->size = r->base = r->offset = 0;
268 return result;
272 * ps3_mm_region_destroy - destroy a memory region
273 * @r: pointer to struct mem_region
276 void ps3_mm_region_destroy(struct mem_region *r)
278 if (r->base) {
279 lv1_release_memory(r->base);
280 r->size = r->base = r->offset = 0;
281 map.total = map.rm.size;
286 * ps3_mm_add_memory - hot add memory
289 static int __init ps3_mm_add_memory(void)
291 int result;
292 unsigned long start_addr;
293 unsigned long start_pfn;
294 unsigned long nr_pages;
296 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
297 return -ENODEV;
299 BUG_ON(!mem_init_done);
301 start_addr = USE_LPAR_ADDR ? map.r1.base : map.rm.size;
302 start_pfn = start_addr >> PAGE_SHIFT;
303 nr_pages = (map.r1.size + PAGE_SIZE - 1) >> PAGE_SHIFT;
305 DBG("%s:%d: start_addr %lxh, start_pfn %lxh, nr_pages %lxh\n",
306 __func__, __LINE__, start_addr, start_pfn, nr_pages);
308 result = add_memory(0, start_addr, map.r1.size);
310 if (result) {
311 DBG("%s:%d: add_memory failed: (%d)\n",
312 __func__, __LINE__, result);
313 return result;
316 result = online_pages(start_pfn, nr_pages);
318 if (result)
319 DBG("%s:%d: online_pages failed: (%d)\n",
320 __func__, __LINE__, result);
322 return result;
325 core_initcall(ps3_mm_add_memory);
327 /*============================================================================*/
328 /* dma routines */
329 /*============================================================================*/
332 * dma_lpar_to_bus - Translate an lpar address to ioc mapped bus address.
333 * @r: pointer to dma region structure
334 * @lpar_addr: HV lpar address
337 static unsigned long dma_lpar_to_bus(struct ps3_dma_region *r,
338 unsigned long lpar_addr)
340 BUG_ON(lpar_addr >= map.r1.base + map.r1.size);
341 return r->bus_addr + (lpar_addr <= map.rm.size ? lpar_addr
342 : lpar_addr - map.r1.offset);
345 #define dma_dump_region(_a) _dma_dump_region(_a, __func__, __LINE__)
346 static void _dma_dump_region(const struct ps3_dma_region *r, const char* func,
347 int line)
349 DBG("%s:%d: dev %u:%u\n", func, line, r->did.bus_id,
350 r->did.dev_id);
351 DBG("%s:%d: page_size %u\n", func, line, r->page_size);
352 DBG("%s:%d: bus_addr %lxh\n", func, line, r->bus_addr);
353 DBG("%s:%d: len %lxh\n", func, line, r->len);
357 * dma_chunk - A chunk of dma pages mapped by the io controller.
358 * @region - The dma region that owns this chunk.
359 * @lpar_addr: Starting lpar address of the area to map.
360 * @bus_addr: Starting ioc bus address of the area to map.
361 * @len: Length in bytes of the area to map.
362 * @link: A struct list_head used with struct ps3_dma_region.chunk_list, the
363 * list of all chuncks owned by the region.
365 * This implementation uses a very simple dma page manager
366 * based on the dma_chunk structure. This scheme assumes
367 * that all drivers use very well behaved dma ops.
370 struct dma_chunk {
371 struct ps3_dma_region *region;
372 unsigned long lpar_addr;
373 unsigned long bus_addr;
374 unsigned long len;
375 struct list_head link;
376 unsigned int usage_count;
379 #define dma_dump_chunk(_a) _dma_dump_chunk(_a, __func__, __LINE__)
380 static void _dma_dump_chunk (const struct dma_chunk* c, const char* func,
381 int line)
383 DBG("%s:%d: r.dev %u:%u\n", func, line,
384 c->region->did.bus_id, c->region->did.dev_id);
385 DBG("%s:%d: r.bus_addr %lxh\n", func, line, c->region->bus_addr);
386 DBG("%s:%d: r.page_size %u\n", func, line, c->region->page_size);
387 DBG("%s:%d: r.len %lxh\n", func, line, c->region->len);
388 DBG("%s:%d: c.lpar_addr %lxh\n", func, line, c->lpar_addr);
389 DBG("%s:%d: c.bus_addr %lxh\n", func, line, c->bus_addr);
390 DBG("%s:%d: c.len %lxh\n", func, line, c->len);
393 static struct dma_chunk * dma_find_chunk(struct ps3_dma_region *r,
394 unsigned long bus_addr, unsigned long len)
396 struct dma_chunk *c;
397 unsigned long aligned_bus = _ALIGN_DOWN(bus_addr, 1 << r->page_size);
398 unsigned long aligned_len = _ALIGN_UP(len, 1 << r->page_size);
400 list_for_each_entry(c, &r->chunk_list.head, link) {
401 /* intersection */
402 if (aligned_bus >= c->bus_addr
403 && aligned_bus < c->bus_addr + c->len
404 && aligned_bus + aligned_len <= c->bus_addr + c->len) {
405 return c;
407 /* below */
408 if (aligned_bus + aligned_len <= c->bus_addr) {
409 continue;
411 /* above */
412 if (aligned_bus >= c->bus_addr + c->len) {
413 continue;
416 /* we don't handle the multi-chunk case for now */
418 dma_dump_chunk(c);
419 BUG();
421 return NULL;
424 static int dma_free_chunk(struct dma_chunk *c)
426 int result = 0;
428 if (c->bus_addr) {
429 result = lv1_unmap_device_dma_region(c->region->did.bus_id,
430 c->region->did.dev_id, c->bus_addr, c->len);
431 BUG_ON(result);
434 kfree(c);
435 return result;
439 * dma_map_pages - Maps dma pages into the io controller bus address space.
440 * @r: Pointer to a struct ps3_dma_region.
441 * @phys_addr: Starting physical address of the area to map.
442 * @len: Length in bytes of the area to map.
443 * c_out: A pointer to receive an allocated struct dma_chunk for this area.
445 * This is the lowest level dma mapping routine, and is the one that will
446 * make the HV call to add the pages into the io controller address space.
449 static int dma_map_pages(struct ps3_dma_region *r, unsigned long phys_addr,
450 unsigned long len, struct dma_chunk **c_out)
452 int result;
453 struct dma_chunk *c;
455 c = kzalloc(sizeof(struct dma_chunk), GFP_ATOMIC);
457 if (!c) {
458 result = -ENOMEM;
459 goto fail_alloc;
462 c->region = r;
463 c->lpar_addr = ps3_mm_phys_to_lpar(phys_addr);
464 c->bus_addr = dma_lpar_to_bus(r, c->lpar_addr);
465 c->len = len;
467 result = lv1_map_device_dma_region(c->region->did.bus_id,
468 c->region->did.dev_id, c->lpar_addr, c->bus_addr, c->len,
469 0xf800000000000000UL);
471 if (result) {
472 DBG("%s:%d: lv1_map_device_dma_region failed: %s\n",
473 __func__, __LINE__, ps3_result(result));
474 goto fail_map;
477 list_add(&c->link, &r->chunk_list.head);
479 *c_out = c;
480 return 0;
482 fail_map:
483 kfree(c);
484 fail_alloc:
485 *c_out = NULL;
486 DBG(" <- %s:%d\n", __func__, __LINE__);
487 return result;
491 * dma_region_create - Create a device dma region.
492 * @r: Pointer to a struct ps3_dma_region.
494 * This is the lowest level dma region create routine, and is the one that
495 * will make the HV call to create the region.
498 static int dma_region_create(struct ps3_dma_region* r)
500 int result;
502 r->len = _ALIGN_UP(map.total, 1 << r->page_size);
503 INIT_LIST_HEAD(&r->chunk_list.head);
504 spin_lock_init(&r->chunk_list.lock);
506 result = lv1_allocate_device_dma_region(r->did.bus_id, r->did.dev_id,
507 r->len, r->page_size, r->region_type, &r->bus_addr);
509 dma_dump_region(r);
511 if (result) {
512 DBG("%s:%d: lv1_allocate_device_dma_region failed: %s\n",
513 __func__, __LINE__, ps3_result(result));
514 r->len = r->bus_addr = 0;
517 return result;
521 * dma_region_free - Free a device dma region.
522 * @r: Pointer to a struct ps3_dma_region.
524 * This is the lowest level dma region free routine, and is the one that
525 * will make the HV call to free the region.
528 static int dma_region_free(struct ps3_dma_region* r)
530 int result;
531 struct dma_chunk *c;
532 struct dma_chunk *tmp;
534 list_for_each_entry_safe(c, tmp, &r->chunk_list.head, link) {
535 list_del(&c->link);
536 dma_free_chunk(c);
539 result = lv1_free_device_dma_region(r->did.bus_id, r->did.dev_id,
540 r->bus_addr);
542 if (result)
543 DBG("%s:%d: lv1_free_device_dma_region failed: %s\n",
544 __func__, __LINE__, ps3_result(result));
546 r->len = r->bus_addr = 0;
548 return result;
552 * dma_map_area - Map an area of memory into a device dma region.
553 * @r: Pointer to a struct ps3_dma_region.
554 * @virt_addr: Starting virtual address of the area to map.
555 * @len: Length in bytes of the area to map.
556 * @bus_addr: A pointer to return the starting ioc bus address of the area to
557 * map.
559 * This is the common dma mapping routine.
562 static int dma_map_area(struct ps3_dma_region *r, unsigned long virt_addr,
563 unsigned long len, unsigned long *bus_addr)
565 int result;
566 unsigned long flags;
567 struct dma_chunk *c;
568 unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr)
569 : virt_addr;
571 *bus_addr = dma_lpar_to_bus(r, ps3_mm_phys_to_lpar(phys_addr));
573 if (!USE_DYNAMIC_DMA) {
574 unsigned long lpar_addr = ps3_mm_phys_to_lpar(phys_addr);
575 DBG(" -> %s:%d\n", __func__, __LINE__);
576 DBG("%s:%d virt_addr %lxh\n", __func__, __LINE__,
577 virt_addr);
578 DBG("%s:%d phys_addr %lxh\n", __func__, __LINE__,
579 phys_addr);
580 DBG("%s:%d lpar_addr %lxh\n", __func__, __LINE__,
581 lpar_addr);
582 DBG("%s:%d len %lxh\n", __func__, __LINE__, len);
583 DBG("%s:%d bus_addr %lxh (%lxh)\n", __func__, __LINE__,
584 *bus_addr, len);
587 spin_lock_irqsave(&r->chunk_list.lock, flags);
588 c = dma_find_chunk(r, *bus_addr, len);
590 if (c) {
591 c->usage_count++;
592 spin_unlock_irqrestore(&r->chunk_list.lock, flags);
593 return 0;
596 result = dma_map_pages(r, _ALIGN_DOWN(phys_addr, 1 << r->page_size),
597 _ALIGN_UP(len, 1 << r->page_size), &c);
599 if (result) {
600 *bus_addr = 0;
601 DBG("%s:%d: dma_map_pages failed (%d)\n",
602 __func__, __LINE__, result);
603 spin_unlock_irqrestore(&r->chunk_list.lock, flags);
604 return result;
607 c->usage_count = 1;
609 spin_unlock_irqrestore(&r->chunk_list.lock, flags);
610 return result;
614 * dma_unmap_area - Unmap an area of memory from a device dma region.
615 * @r: Pointer to a struct ps3_dma_region.
616 * @bus_addr: The starting ioc bus address of the area to unmap.
617 * @len: Length in bytes of the area to unmap.
619 * This is the common dma unmap routine.
622 int dma_unmap_area(struct ps3_dma_region *r, unsigned long bus_addr,
623 unsigned long len)
625 unsigned long flags;
626 struct dma_chunk *c;
628 spin_lock_irqsave(&r->chunk_list.lock, flags);
629 c = dma_find_chunk(r, bus_addr, len);
631 if (!c) {
632 unsigned long aligned_bus = _ALIGN_DOWN(bus_addr,
633 1 << r->page_size);
634 unsigned long aligned_len = _ALIGN_UP(len, 1 << r->page_size);
635 DBG("%s:%d: not found: bus_addr %lxh\n",
636 __func__, __LINE__, bus_addr);
637 DBG("%s:%d: not found: len %lxh\n",
638 __func__, __LINE__, len);
639 DBG("%s:%d: not found: aligned_bus %lxh\n",
640 __func__, __LINE__, aligned_bus);
641 DBG("%s:%d: not found: aligned_len %lxh\n",
642 __func__, __LINE__, aligned_len);
643 BUG();
646 c->usage_count--;
648 if (!c->usage_count) {
649 list_del(&c->link);
650 dma_free_chunk(c);
653 spin_unlock_irqrestore(&r->chunk_list.lock, flags);
654 return 0;
658 * dma_region_create_linear - Setup a linear dma maping for a device.
659 * @r: Pointer to a struct ps3_dma_region.
661 * This routine creates an HV dma region for the device and maps all available
662 * ram into the io controller bus address space.
665 static int dma_region_create_linear(struct ps3_dma_region *r)
667 int result;
668 unsigned long tmp;
670 /* force 16M dma pages for linear mapping */
672 if (r->page_size != PS3_DMA_16M) {
673 pr_info("%s:%d: forcing 16M pages for linear map\n",
674 __func__, __LINE__);
675 r->page_size = PS3_DMA_16M;
678 result = dma_region_create(r);
679 BUG_ON(result);
681 result = dma_map_area(r, map.rm.base, map.rm.size, &tmp);
682 BUG_ON(result);
684 if (USE_LPAR_ADDR)
685 result = dma_map_area(r, map.r1.base, map.r1.size,
686 &tmp);
687 else
688 result = dma_map_area(r, map.rm.size, map.r1.size,
689 &tmp);
691 BUG_ON(result);
693 return result;
697 * dma_region_free_linear - Free a linear dma mapping for a device.
698 * @r: Pointer to a struct ps3_dma_region.
700 * This routine will unmap all mapped areas and free the HV dma region.
703 static int dma_region_free_linear(struct ps3_dma_region *r)
705 int result;
707 result = dma_unmap_area(r, dma_lpar_to_bus(r, 0), map.rm.size);
708 BUG_ON(result);
710 result = dma_unmap_area(r, dma_lpar_to_bus(r, map.r1.base),
711 map.r1.size);
712 BUG_ON(result);
714 result = dma_region_free(r);
715 BUG_ON(result);
717 return result;
721 * dma_map_area_linear - Map an area of memory into a device dma region.
722 * @r: Pointer to a struct ps3_dma_region.
723 * @virt_addr: Starting virtual address of the area to map.
724 * @len: Length in bytes of the area to map.
725 * @bus_addr: A pointer to return the starting ioc bus address of the area to
726 * map.
728 * This routine just returns the coresponding bus address. Actual mapping
729 * occurs in dma_region_create_linear().
732 static int dma_map_area_linear(struct ps3_dma_region *r,
733 unsigned long virt_addr, unsigned long len, unsigned long *bus_addr)
735 unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr)
736 : virt_addr;
737 *bus_addr = dma_lpar_to_bus(r, ps3_mm_phys_to_lpar(phys_addr));
738 return 0;
742 * dma_unmap_area_linear - Unmap an area of memory from a device dma region.
743 * @r: Pointer to a struct ps3_dma_region.
744 * @bus_addr: The starting ioc bus address of the area to unmap.
745 * @len: Length in bytes of the area to unmap.
747 * This routine does nothing. Unmapping occurs in dma_region_free_linear().
750 static int dma_unmap_area_linear(struct ps3_dma_region *r,
751 unsigned long bus_addr, unsigned long len)
753 return 0;
756 int ps3_dma_region_create(struct ps3_dma_region *r)
758 return (USE_DYNAMIC_DMA)
759 ? dma_region_create(r)
760 : dma_region_create_linear(r);
763 int ps3_dma_region_free(struct ps3_dma_region *r)
765 return (USE_DYNAMIC_DMA)
766 ? dma_region_free(r)
767 : dma_region_free_linear(r);
770 int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr,
771 unsigned long len, unsigned long *bus_addr)
773 return (USE_DYNAMIC_DMA)
774 ? dma_map_area(r, virt_addr, len, bus_addr)
775 : dma_map_area_linear(r, virt_addr, len, bus_addr);
778 int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long bus_addr,
779 unsigned long len)
781 return (USE_DYNAMIC_DMA) ? dma_unmap_area(r, bus_addr, len)
782 : dma_unmap_area_linear(r, bus_addr, len);
785 /*============================================================================*/
786 /* system startup routines */
787 /*============================================================================*/
790 * ps3_mm_init - initialize the address space state variables
793 void __init ps3_mm_init(void)
795 int result;
797 DBG(" -> %s:%d\n", __func__, __LINE__);
799 result = ps3_repository_read_mm_info(&map.rm.base, &map.rm.size,
800 &map.total);
802 if (result)
803 panic("ps3_repository_read_mm_info() failed");
805 map.rm.offset = map.rm.base;
806 map.vas_id = map.htab_size = 0;
808 /* this implementation assumes map.rm.base is zero */
810 BUG_ON(map.rm.base);
811 BUG_ON(!map.rm.size);
813 lmb_add(map.rm.base, map.rm.size);
814 lmb_analyze();
816 /* arrange to do this in ps3_mm_add_memory */
817 ps3_mm_region_create(&map.r1, map.total - map.rm.size);
819 DBG(" <- %s:%d\n", __func__, __LINE__);
823 * ps3_mm_shutdown - final cleanup of address space
826 void ps3_mm_shutdown(void)
828 ps3_mm_region_destroy(&map.r1);