mm.c (75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37) mm.c (e96d904ede6756641563d27daa746875b478a6c8)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * PS3 address space management.
4 *
5 * Copyright (C) 2006 Sony Computer Entertainment Inc.
6 * Copyright 2006 Sony Corp.
7 */
8

--- 249 unchanged lines hidden (view full) ---

258 * @size is rounded down to a multiple of the vas large page size.
259 */
260
261static int ps3_mm_region_create(struct mem_region *r, unsigned long size)
262{
263 int result;
264 u64 muid;
265
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * PS3 address space management.
4 *
5 * Copyright (C) 2006 Sony Computer Entertainment Inc.
6 * Copyright 2006 Sony Corp.
7 */
8

--- 249 unchanged lines hidden (view full) ---

258 * @size is rounded down to a multiple of the vas large page size.
259 */
260
261static int ps3_mm_region_create(struct mem_region *r, unsigned long size)
262{
263 int result;
264 u64 muid;
265
266 r->size = _ALIGN_DOWN(size, 1 << PAGE_SHIFT_16M);
266 r->size = ALIGN_DOWN(size, 1 << PAGE_SHIFT_16M);
267
268 DBG("%s:%d requested %lxh\n", __func__, __LINE__, size);
269 DBG("%s:%d actual %llxh\n", __func__, __LINE__, r->size);
270 DBG("%s:%d difference %llxh (%lluMB)\n", __func__, __LINE__,
271 size - r->size, (size - r->size) / 1024 / 1024);
272
273 if (r->size == 0) {
274 DBG("%s:%d: size == 0\n", __func__, __LINE__);

--- 114 unchanged lines hidden (view full) ---

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);
391}
392
393static struct dma_chunk * dma_find_chunk(struct ps3_dma_region *r,
394 unsigned long bus_addr, unsigned long len)
395{
396 struct dma_chunk *c;
267
268 DBG("%s:%d requested %lxh\n", __func__, __LINE__, size);
269 DBG("%s:%d actual %llxh\n", __func__, __LINE__, r->size);
270 DBG("%s:%d difference %llxh (%lluMB)\n", __func__, __LINE__,
271 size - r->size, (size - r->size) / 1024 / 1024);
272
273 if (r->size == 0) {
274 DBG("%s:%d: size == 0\n", __func__, __LINE__);

--- 114 unchanged lines hidden (view full) ---

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);
391}
392
393static struct dma_chunk * dma_find_chunk(struct ps3_dma_region *r,
394 unsigned long bus_addr, unsigned long len)
395{
396 struct dma_chunk *c;
397 unsigned long aligned_bus = _ALIGN_DOWN(bus_addr, 1 << r->page_size);
397 unsigned long aligned_bus = ALIGN_DOWN(bus_addr, 1 << r->page_size);
398 unsigned long aligned_len = _ALIGN_UP(len+bus_addr-aligned_bus,
399 1 << r->page_size);
400
401 list_for_each_entry(c, &r->chunk_list.head, link) {
402 /* intersection */
403 if (aligned_bus >= c->bus_addr &&
404 aligned_bus + aligned_len <= c->bus_addr + c->len)
405 return c;

--- 12 unchanged lines hidden (view full) ---

418 }
419 return NULL;
420}
421
422static struct dma_chunk *dma_find_chunk_lpar(struct ps3_dma_region *r,
423 unsigned long lpar_addr, unsigned long len)
424{
425 struct dma_chunk *c;
398 unsigned long aligned_len = _ALIGN_UP(len+bus_addr-aligned_bus,
399 1 << r->page_size);
400
401 list_for_each_entry(c, &r->chunk_list.head, link) {
402 /* intersection */
403 if (aligned_bus >= c->bus_addr &&
404 aligned_bus + aligned_len <= c->bus_addr + c->len)
405 return c;

--- 12 unchanged lines hidden (view full) ---

418 }
419 return NULL;
420}
421
422static struct dma_chunk *dma_find_chunk_lpar(struct ps3_dma_region *r,
423 unsigned long lpar_addr, unsigned long len)
424{
425 struct dma_chunk *c;
426 unsigned long aligned_lpar = _ALIGN_DOWN(lpar_addr, 1 << r->page_size);
426 unsigned long aligned_lpar = ALIGN_DOWN(lpar_addr, 1 << r->page_size);
427 unsigned long aligned_len = _ALIGN_UP(len + lpar_addr - aligned_lpar,
428 1 << r->page_size);
429
430 list_for_each_entry(c, &r->chunk_list.head, link) {
431 /* intersection */
432 if (c->lpar_addr <= aligned_lpar &&
433 aligned_lpar < c->lpar_addr + c->len) {
434 if (aligned_lpar + aligned_len <= c->lpar_addr + c->len)

--- 335 unchanged lines hidden (view full) ---

770 unsigned long len, dma_addr_t *bus_addr,
771 u64 iopte_flag)
772{
773 int result;
774 unsigned long flags;
775 struct dma_chunk *c;
776 unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr)
777 : virt_addr;
427 unsigned long aligned_len = _ALIGN_UP(len + lpar_addr - aligned_lpar,
428 1 << r->page_size);
429
430 list_for_each_entry(c, &r->chunk_list.head, link) {
431 /* intersection */
432 if (c->lpar_addr <= aligned_lpar &&
433 aligned_lpar < c->lpar_addr + c->len) {
434 if (aligned_lpar + aligned_len <= c->lpar_addr + c->len)

--- 335 unchanged lines hidden (view full) ---

770 unsigned long len, dma_addr_t *bus_addr,
771 u64 iopte_flag)
772{
773 int result;
774 unsigned long flags;
775 struct dma_chunk *c;
776 unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr)
777 : virt_addr;
778 unsigned long aligned_phys = _ALIGN_DOWN(phys_addr, 1 << r->page_size);
778 unsigned long aligned_phys = ALIGN_DOWN(phys_addr, 1 << r->page_size);
779 unsigned long aligned_len = _ALIGN_UP(len + phys_addr - aligned_phys,
780 1 << r->page_size);
781 *bus_addr = dma_sb_lpar_to_bus(r, ps3_mm_phys_to_lpar(phys_addr));
782
783 if (!USE_DYNAMIC_DMA) {
784 unsigned long lpar_addr = ps3_mm_phys_to_lpar(phys_addr);
785 DBG(" -> %s:%d\n", __func__, __LINE__);
786 DBG("%s:%d virt_addr %lxh\n", __func__, __LINE__,

--- 38 unchanged lines hidden (view full) ---

825 unsigned long len, dma_addr_t *bus_addr,
826 u64 iopte_flag)
827{
828 int result;
829 unsigned long flags;
830 struct dma_chunk *c;
831 unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr)
832 : virt_addr;
779 unsigned long aligned_len = _ALIGN_UP(len + phys_addr - aligned_phys,
780 1 << r->page_size);
781 *bus_addr = dma_sb_lpar_to_bus(r, ps3_mm_phys_to_lpar(phys_addr));
782
783 if (!USE_DYNAMIC_DMA) {
784 unsigned long lpar_addr = ps3_mm_phys_to_lpar(phys_addr);
785 DBG(" -> %s:%d\n", __func__, __LINE__);
786 DBG("%s:%d virt_addr %lxh\n", __func__, __LINE__,

--- 38 unchanged lines hidden (view full) ---

825 unsigned long len, dma_addr_t *bus_addr,
826 u64 iopte_flag)
827{
828 int result;
829 unsigned long flags;
830 struct dma_chunk *c;
831 unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr)
832 : virt_addr;
833 unsigned long aligned_phys = _ALIGN_DOWN(phys_addr, 1 << r->page_size);
833 unsigned long aligned_phys = ALIGN_DOWN(phys_addr, 1 << r->page_size);
834 unsigned long aligned_len = _ALIGN_UP(len + phys_addr - aligned_phys,
835 1 << r->page_size);
836
837 DBG(KERN_ERR "%s: vaddr=%#lx, len=%#lx\n", __func__,
838 virt_addr, len);
839 DBG(KERN_ERR "%s: ph=%#lx a_ph=%#lx a_l=%#lx\n", __func__,
840 phys_addr, aligned_phys, aligned_len);
841

--- 42 unchanged lines hidden (view full) ---

884{
885 unsigned long flags;
886 struct dma_chunk *c;
887
888 spin_lock_irqsave(&r->chunk_list.lock, flags);
889 c = dma_find_chunk(r, bus_addr, len);
890
891 if (!c) {
834 unsigned long aligned_len = _ALIGN_UP(len + phys_addr - aligned_phys,
835 1 << r->page_size);
836
837 DBG(KERN_ERR "%s: vaddr=%#lx, len=%#lx\n", __func__,
838 virt_addr, len);
839 DBG(KERN_ERR "%s: ph=%#lx a_ph=%#lx a_l=%#lx\n", __func__,
840 phys_addr, aligned_phys, aligned_len);
841

--- 42 unchanged lines hidden (view full) ---

884{
885 unsigned long flags;
886 struct dma_chunk *c;
887
888 spin_lock_irqsave(&r->chunk_list.lock, flags);
889 c = dma_find_chunk(r, bus_addr, len);
890
891 if (!c) {
892 unsigned long aligned_bus = _ALIGN_DOWN(bus_addr,
892 unsigned long aligned_bus = ALIGN_DOWN(bus_addr,
893 1 << r->page_size);
894 unsigned long aligned_len = _ALIGN_UP(len + bus_addr
895 - aligned_bus, 1 << r->page_size);
896 DBG("%s:%d: not found: bus_addr %llxh\n",
897 __func__, __LINE__, bus_addr);
898 DBG("%s:%d: not found: len %lxh\n",
899 __func__, __LINE__, len);
900 DBG("%s:%d: not found: aligned_bus %lxh\n",

--- 20 unchanged lines hidden (view full) ---

921 unsigned long flags;
922 struct dma_chunk *c;
923
924 DBG("%s: start a=%#llx l=%#lx\n", __func__, bus_addr, len);
925 spin_lock_irqsave(&r->chunk_list.lock, flags);
926 c = dma_find_chunk(r, bus_addr, len);
927
928 if (!c) {
893 1 << r->page_size);
894 unsigned long aligned_len = _ALIGN_UP(len + bus_addr
895 - aligned_bus, 1 << r->page_size);
896 DBG("%s:%d: not found: bus_addr %llxh\n",
897 __func__, __LINE__, bus_addr);
898 DBG("%s:%d: not found: len %lxh\n",
899 __func__, __LINE__, len);
900 DBG("%s:%d: not found: aligned_bus %lxh\n",

--- 20 unchanged lines hidden (view full) ---

921 unsigned long flags;
922 struct dma_chunk *c;
923
924 DBG("%s: start a=%#llx l=%#lx\n", __func__, bus_addr, len);
925 spin_lock_irqsave(&r->chunk_list.lock, flags);
926 c = dma_find_chunk(r, bus_addr, len);
927
928 if (!c) {
929 unsigned long aligned_bus = _ALIGN_DOWN(bus_addr,
929 unsigned long aligned_bus = ALIGN_DOWN(bus_addr,
930 1 << r->page_size);
931 unsigned long aligned_len = _ALIGN_UP(len + bus_addr
932 - aligned_bus,
933 1 << r->page_size);
934 DBG("%s:%d: not found: bus_addr %llxh\n",
935 __func__, __LINE__, bus_addr);
936 DBG("%s:%d: not found: len %lxh\n",
937 __func__, __LINE__, len);

--- 300 unchanged lines hidden ---
930 1 << r->page_size);
931 unsigned long aligned_len = _ALIGN_UP(len + bus_addr
932 - aligned_bus,
933 1 << r->page_size);
934 DBG("%s:%d: not found: bus_addr %llxh\n",
935 __func__, __LINE__, bus_addr);
936 DBG("%s:%d: not found: len %lxh\n",
937 __func__, __LINE__, len);

--- 300 unchanged lines hidden ---