Lines Matching full:r
215 static int ps3_mm_get_repository_highmem(struct mem_region *r) in ps3_mm_get_repository_highmem() argument
221 result = ps3_repository_read_highmem_info(0, &r->base, &r->size); in ps3_mm_get_repository_highmem()
226 if (!r->base || !r->size) { in ps3_mm_get_repository_highmem()
231 r->offset = r->base - map.rm.size; in ps3_mm_get_repository_highmem()
234 __func__, __LINE__, r->base, r->size); in ps3_mm_get_repository_highmem()
241 r->size = r->base = r->offset = 0; in ps3_mm_get_repository_highmem()
245 static int ps3_mm_set_repository_highmem(const struct mem_region *r) in ps3_mm_set_repository_highmem() argument
249 return r ? ps3_repository_write_highmem_info(0, r->base, r->size) : in ps3_mm_set_repository_highmem()
255 * @r: pointer to a struct mem_region to accept initialized values
262 static int ps3_mm_region_create(struct mem_region *r, unsigned long size) in ps3_mm_region_create() argument
267 r->size = ALIGN_DOWN(size, 1 << PAGE_SHIFT_16M); in ps3_mm_region_create()
270 DBG("%s:%d actual %llxh\n", __func__, __LINE__, r->size); in ps3_mm_region_create()
272 size - r->size, (size - r->size) / 1024 / 1024); in ps3_mm_region_create()
274 if (r->size == 0) { in ps3_mm_region_create()
280 result = lv1_allocate_memory(r->size, PAGE_SHIFT_16M, 0, in ps3_mm_region_create()
281 ALLOCATE_MEMORY_TRY_ALT_UNIT, &r->base, &muid); in ps3_mm_region_create()
283 if (result || r->base < map.rm.size) { in ps3_mm_region_create()
289 r->destroy = 1; in ps3_mm_region_create()
290 r->offset = r->base - map.rm.size; in ps3_mm_region_create()
294 r->size = r->base = r->offset = 0; in ps3_mm_region_create()
300 * @r: pointer to struct mem_region
303 static void ps3_mm_region_destroy(struct mem_region *r) in ps3_mm_region_destroy() argument
307 if (!r->destroy) { in ps3_mm_region_destroy()
311 if (r->base) { in ps3_mm_region_destroy()
312 result = lv1_release_memory(r->base); in ps3_mm_region_destroy()
318 r->size = r->base = r->offset = 0; in ps3_mm_region_destroy()
331 * @r: pointer to dma region structure
335 static unsigned long dma_sb_lpar_to_bus(struct ps3_dma_region *r, in dma_sb_lpar_to_bus() argument
340 BUG_ON(lpar_addr < r->offset); in dma_sb_lpar_to_bus()
341 BUG_ON(lpar_addr >= r->offset + r->len); in dma_sb_lpar_to_bus()
342 return r->bus_addr + lpar_addr - r->offset; in dma_sb_lpar_to_bus()
346 static void __maybe_unused _dma_dump_region(const struct ps3_dma_region *r, in _dma_dump_region() argument
349 DBG("%s:%d: dev %llu:%llu\n", func, line, r->dev->bus_id, in _dma_dump_region()
350 r->dev->dev_id); in _dma_dump_region()
351 DBG("%s:%d: page_size %u\n", func, line, r->page_size); in _dma_dump_region()
352 DBG("%s:%d: bus_addr %lxh\n", func, line, r->bus_addr); in _dma_dump_region()
353 DBG("%s:%d: len %lxh\n", func, line, r->len); in _dma_dump_region()
354 DBG("%s:%d: offset %lxh\n", func, line, r->offset); in _dma_dump_region()
384 DBG("%s:%d: r.dev %llu:%llu\n", func, line, in _dma_dump_chunk()
386 DBG("%s:%d: r.bus_addr %lxh\n", func, line, c->region->bus_addr); in _dma_dump_chunk()
387 DBG("%s:%d: r.page_size %u\n", func, line, c->region->page_size); in _dma_dump_chunk()
388 DBG("%s:%d: r.len %lxh\n", func, line, c->region->len); in _dma_dump_chunk()
389 DBG("%s:%d: r.offset %lxh\n", func, line, c->region->offset); in _dma_dump_chunk()
395 static struct dma_chunk * dma_find_chunk(struct ps3_dma_region *r, in dma_find_chunk() argument
399 unsigned long aligned_bus = ALIGN_DOWN(bus_addr, 1 << r->page_size); in dma_find_chunk()
401 1 << r->page_size); in dma_find_chunk()
403 list_for_each_entry(c, &r->chunk_list.head, link) { in dma_find_chunk()
424 static struct dma_chunk *dma_find_chunk_lpar(struct ps3_dma_region *r, in dma_find_chunk_lpar() argument
428 unsigned long aligned_lpar = ALIGN_DOWN(lpar_addr, 1 << r->page_size); in dma_find_chunk_lpar()
430 1 << r->page_size); in dma_find_chunk_lpar()
432 list_for_each_entry(c, &r->chunk_list.head, link) { in dma_find_chunk_lpar()
474 struct ps3_dma_region *r = c->region; in dma_ioc0_free_chunk() local
477 for (iopage = 0; iopage < (c->len >> r->page_size); iopage++) { in dma_ioc0_free_chunk()
478 offset = (1 << r->page_size) * iopage; in dma_ioc0_free_chunk()
483 r->ioid, in dma_ioc0_free_chunk()
488 r->ioid); in dma_ioc0_free_chunk()
502 * @r: Pointer to a struct ps3_dma_region.
511 static int dma_sb_map_pages(struct ps3_dma_region *r, unsigned long phys_addr, in dma_sb_map_pages() argument
523 c->region = r; in dma_sb_map_pages()
525 c->bus_addr = dma_sb_lpar_to_bus(r, c->lpar_addr); in dma_sb_map_pages()
538 list_add(&c->link, &r->chunk_list.head); in dma_sb_map_pages()
551 static int dma_ioc0_map_pages(struct ps3_dma_region *r, unsigned long phys_addr, in dma_ioc0_map_pages() argument
568 c->region = r; in dma_ioc0_map_pages()
572 if (list_empty(&r->chunk_list.head)) { in dma_ioc0_map_pages()
574 c->bus_addr = r->bus_addr; in dma_ioc0_map_pages()
577 last = list_entry(r->chunk_list.head.next, in dma_ioc0_map_pages()
587 pages = len >> r->page_size; in dma_ioc0_map_pages()
589 r->page_size, r->len, pages, iopte_flag); in dma_ioc0_map_pages()
591 offset = (1 << r->page_size) * iopage; in dma_ioc0_map_pages()
595 r->ioid, in dma_ioc0_map_pages()
604 r->ioid); in dma_ioc0_map_pages()
608 list_add(&c->link, &r->chunk_list.head); in dma_ioc0_map_pages()
619 r->ioid, in dma_ioc0_map_pages()
630 * @r: Pointer to a struct ps3_dma_region.
636 static int dma_sb_region_create(struct ps3_dma_region *r) in dma_sb_region_create() argument
643 BUG_ON(!r); in dma_sb_region_create()
645 if (!r->dev->bus_id) { in dma_sb_region_create()
647 r->dev->bus_id, r->dev->dev_id); in dma_sb_region_create()
652 __LINE__, r->len, r->page_size, r->offset); in dma_sb_region_create()
654 BUG_ON(!r->len); in dma_sb_region_create()
655 BUG_ON(!r->page_size); in dma_sb_region_create()
656 BUG_ON(!r->region_ops); in dma_sb_region_create()
658 INIT_LIST_HEAD(&r->chunk_list.head); in dma_sb_region_create()
659 spin_lock_init(&r->chunk_list.lock); in dma_sb_region_create()
661 result = lv1_allocate_device_dma_region(r->dev->bus_id, r->dev->dev_id, in dma_sb_region_create()
662 roundup_pow_of_two(r->len), r->page_size, r->region_type, in dma_sb_region_create()
664 r->bus_addr = bus_addr; in dma_sb_region_create()
669 r->len = r->bus_addr = 0; in dma_sb_region_create()
675 static int dma_ioc0_region_create(struct ps3_dma_region *r) in dma_ioc0_region_create() argument
680 INIT_LIST_HEAD(&r->chunk_list.head); in dma_ioc0_region_create()
681 spin_lock_init(&r->chunk_list.lock); in dma_ioc0_region_create()
684 r->len, in dma_ioc0_region_create()
685 r->page_size, in dma_ioc0_region_create()
687 r->bus_addr = bus_addr; in dma_ioc0_region_create()
691 r->len = r->bus_addr = 0; in dma_ioc0_region_create()
694 r->len, r->page_size, r->bus_addr); in dma_ioc0_region_create()
700 * @r: Pointer to a struct ps3_dma_region.
706 static int dma_sb_region_free(struct ps3_dma_region *r) in dma_sb_region_free() argument
712 BUG_ON(!r); in dma_sb_region_free()
714 if (!r->dev->bus_id) { in dma_sb_region_free()
716 r->dev->bus_id, r->dev->dev_id); in dma_sb_region_free()
720 list_for_each_entry_safe(c, tmp, &r->chunk_list.head, link) { in dma_sb_region_free()
725 result = lv1_free_device_dma_region(r->dev->bus_id, r->dev->dev_id, in dma_sb_region_free()
726 r->bus_addr); in dma_sb_region_free()
732 r->bus_addr = 0; in dma_sb_region_free()
737 static int dma_ioc0_region_free(struct ps3_dma_region *r) in dma_ioc0_region_free() argument
743 list_for_each_entry_safe(c, n, &r->chunk_list.head, link) { in dma_ioc0_region_free()
748 result = lv1_release_io_segment(0, r->bus_addr); in dma_ioc0_region_free()
754 r->bus_addr = 0; in dma_ioc0_region_free()
762 * @r: Pointer to a struct ps3_dma_region.
771 static int dma_sb_map_area(struct ps3_dma_region *r, unsigned long virt_addr, in dma_sb_map_area() argument
780 unsigned long aligned_phys = ALIGN_DOWN(phys_addr, 1 << r->page_size); in dma_sb_map_area()
782 1 << r->page_size); in dma_sb_map_area()
783 *bus_addr = dma_sb_lpar_to_bus(r, ps3_mm_phys_to_lpar(phys_addr)); in dma_sb_map_area()
799 spin_lock_irqsave(&r->chunk_list.lock, flags); in dma_sb_map_area()
800 c = dma_find_chunk(r, *bus_addr, len); in dma_sb_map_area()
806 spin_unlock_irqrestore(&r->chunk_list.lock, flags); in dma_sb_map_area()
810 result = dma_sb_map_pages(r, aligned_phys, aligned_len, &c, iopte_flag); in dma_sb_map_area()
816 spin_unlock_irqrestore(&r->chunk_list.lock, flags); in dma_sb_map_area()
822 spin_unlock_irqrestore(&r->chunk_list.lock, flags); in dma_sb_map_area()
826 static int dma_ioc0_map_area(struct ps3_dma_region *r, unsigned long virt_addr, in dma_ioc0_map_area() argument
835 unsigned long aligned_phys = ALIGN_DOWN(phys_addr, 1 << r->page_size); in dma_ioc0_map_area()
837 1 << r->page_size); in dma_ioc0_map_area()
844 spin_lock_irqsave(&r->chunk_list.lock, flags); in dma_ioc0_map_area()
845 c = dma_find_chunk_lpar(r, ps3_mm_phys_to_lpar(phys_addr), len); in dma_ioc0_map_area()
852 spin_unlock_irqrestore(&r->chunk_list.lock, flags); in dma_ioc0_map_area()
856 result = dma_ioc0_map_pages(r, aligned_phys, aligned_len, &c, in dma_ioc0_map_area()
863 spin_unlock_irqrestore(&r->chunk_list.lock, flags); in dma_ioc0_map_area()
871 spin_unlock_irqrestore(&r->chunk_list.lock, flags); in dma_ioc0_map_area()
877 * @r: Pointer to a struct ps3_dma_region.
884 static int dma_sb_unmap_area(struct ps3_dma_region *r, dma_addr_t bus_addr, in dma_sb_unmap_area() argument
890 spin_lock_irqsave(&r->chunk_list.lock, flags); in dma_sb_unmap_area()
891 c = dma_find_chunk(r, bus_addr, len); in dma_sb_unmap_area()
895 1 << r->page_size); in dma_sb_unmap_area()
897 - aligned_bus, 1 << r->page_size); in dma_sb_unmap_area()
916 spin_unlock_irqrestore(&r->chunk_list.lock, flags); in dma_sb_unmap_area()
920 static int dma_ioc0_unmap_area(struct ps3_dma_region *r, in dma_ioc0_unmap_area() argument
927 spin_lock_irqsave(&r->chunk_list.lock, flags); in dma_ioc0_unmap_area()
928 c = dma_find_chunk(r, bus_addr, len); in dma_ioc0_unmap_area()
932 1 << r->page_size); in dma_ioc0_unmap_area()
935 1 << r->page_size); in dma_ioc0_unmap_area()
954 spin_unlock_irqrestore(&r->chunk_list.lock, flags); in dma_ioc0_unmap_area()
961 * @r: Pointer to a struct ps3_dma_region.
967 static int dma_sb_region_create_linear(struct ps3_dma_region *r) in dma_sb_region_create_linear() argument
973 if (r->len > 16*1024*1024) { /* FIXME: need proper fix */ in dma_sb_region_create_linear()
975 if (r->page_size != PS3_DMA_16M) { in dma_sb_region_create_linear()
978 r->page_size = PS3_DMA_16M; in dma_sb_region_create_linear()
979 r->len = ALIGN(r->len, 1 << r->page_size); in dma_sb_region_create_linear()
983 result = dma_sb_region_create(r); in dma_sb_region_create_linear()
986 if (r->offset < map.rm.size) { in dma_sb_region_create_linear()
988 virt_addr = map.rm.base + r->offset; in dma_sb_region_create_linear()
989 len = map.rm.size - r->offset; in dma_sb_region_create_linear()
990 if (len > r->len) in dma_sb_region_create_linear()
991 len = r->len; in dma_sb_region_create_linear()
992 result = dma_sb_map_area(r, virt_addr, len, &tmp, in dma_sb_region_create_linear()
998 if (r->offset + r->len > map.rm.size) { in dma_sb_region_create_linear()
1001 len = r->len; in dma_sb_region_create_linear()
1002 if (r->offset >= map.rm.size) in dma_sb_region_create_linear()
1003 virt_addr += r->offset - map.rm.size; in dma_sb_region_create_linear()
1005 len -= map.rm.size - r->offset; in dma_sb_region_create_linear()
1006 result = dma_sb_map_area(r, virt_addr, len, &tmp, in dma_sb_region_create_linear()
1017 * @r: Pointer to a struct ps3_dma_region.
1022 static int dma_sb_region_free_linear(struct ps3_dma_region *r) in dma_sb_region_free_linear() argument
1028 if (r->offset < map.rm.size) { in dma_sb_region_free_linear()
1030 lpar_addr = map.rm.base + r->offset; in dma_sb_region_free_linear()
1031 len = map.rm.size - r->offset; in dma_sb_region_free_linear()
1032 if (len > r->len) in dma_sb_region_free_linear()
1033 len = r->len; in dma_sb_region_free_linear()
1034 bus_addr = dma_sb_lpar_to_bus(r, lpar_addr); in dma_sb_region_free_linear()
1035 result = dma_sb_unmap_area(r, bus_addr, len); in dma_sb_region_free_linear()
1039 if (r->offset + r->len > map.rm.size) { in dma_sb_region_free_linear()
1042 len = r->len; in dma_sb_region_free_linear()
1043 if (r->offset >= map.rm.size) in dma_sb_region_free_linear()
1044 lpar_addr += r->offset - map.rm.size; in dma_sb_region_free_linear()
1046 len -= map.rm.size - r->offset; in dma_sb_region_free_linear()
1047 bus_addr = dma_sb_lpar_to_bus(r, lpar_addr); in dma_sb_region_free_linear()
1048 result = dma_sb_unmap_area(r, bus_addr, len); in dma_sb_region_free_linear()
1052 result = dma_sb_region_free(r); in dma_sb_region_free_linear()
1060 * @r: Pointer to a struct ps3_dma_region.
1070 static int dma_sb_map_area_linear(struct ps3_dma_region *r, in dma_sb_map_area_linear() argument
1076 *bus_addr = dma_sb_lpar_to_bus(r, ps3_mm_phys_to_lpar(phys_addr)); in dma_sb_map_area_linear()
1082 * @r: Pointer to a struct ps3_dma_region.
1089 static int dma_sb_unmap_area_linear(struct ps3_dma_region *r, in dma_sb_unmap_area_linear() argument
1117 struct ps3_dma_region *r, enum ps3_dma_page_size page_size, in ps3_dma_region_init() argument
1124 r->dev = dev; in ps3_dma_region_init()
1125 r->page_size = page_size; in ps3_dma_region_init()
1126 r->region_type = region_type; in ps3_dma_region_init()
1127 r->offset = lpar_addr; in ps3_dma_region_init()
1128 if (r->offset >= map.rm.size) in ps3_dma_region_init()
1129 r->offset -= map.r1.offset; in ps3_dma_region_init()
1130 r->len = len ? len : ALIGN(map.total, 1 << r->page_size); in ps3_dma_region_init()
1134 r->region_ops = (USE_DYNAMIC_DMA) in ps3_dma_region_init()
1139 r->region_ops = &ps3_dma_ioc0_region_ops; in ps3_dma_region_init()
1149 int ps3_dma_region_create(struct ps3_dma_region *r) in ps3_dma_region_create() argument
1151 BUG_ON(!r); in ps3_dma_region_create()
1152 BUG_ON(!r->region_ops); in ps3_dma_region_create()
1153 BUG_ON(!r->region_ops->create); in ps3_dma_region_create()
1154 return r->region_ops->create(r); in ps3_dma_region_create()
1158 int ps3_dma_region_free(struct ps3_dma_region *r) in ps3_dma_region_free() argument
1160 BUG_ON(!r); in ps3_dma_region_free()
1161 BUG_ON(!r->region_ops); in ps3_dma_region_free()
1162 BUG_ON(!r->region_ops->free); in ps3_dma_region_free()
1163 return r->region_ops->free(r); in ps3_dma_region_free()
1167 int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr, in ps3_dma_map() argument
1171 return r->region_ops->map(r, virt_addr, len, bus_addr, iopte_flag); in ps3_dma_map()
1174 int ps3_dma_unmap(struct ps3_dma_region *r, dma_addr_t bus_addr, in ps3_dma_unmap() argument
1177 return r->region_ops->unmap(r, bus_addr, len); in ps3_dma_unmap()