Commit 54d04ea8 authored by Christian König's avatar Christian König

drm/ttm: merge offset and base in ttm_bus_placement

This is used by TTM to communicate the physical address
which should be used with ioremap(), ioremap_wc(). We don't
need to separate the base and offset in any way here.
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarDave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/389457/
parent 1ff67ce4
...@@ -773,7 +773,7 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso ...@@ -773,7 +773,7 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso
mem->bus.addr = (u8 *)adev->mman.aper_base_kaddr + mem->bus.addr = (u8 *)adev->mman.aper_base_kaddr +
mem->bus.offset; mem->bus.offset;
mem->bus.base = adev->gmc.aper_base; mem->bus.offset += adev->gmc.aper_base;
mem->bus.is_iomem = true; mem->bus.is_iomem = true;
break; break;
default: default:
...@@ -785,12 +785,13 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso ...@@ -785,12 +785,13 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso
static unsigned long amdgpu_ttm_io_mem_pfn(struct ttm_buffer_object *bo, static unsigned long amdgpu_ttm_io_mem_pfn(struct ttm_buffer_object *bo,
unsigned long page_offset) unsigned long page_offset)
{ {
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
uint64_t offset = (page_offset << PAGE_SHIFT); uint64_t offset = (page_offset << PAGE_SHIFT);
struct drm_mm_node *mm; struct drm_mm_node *mm;
mm = amdgpu_find_mm_node(&bo->mem, &offset); mm = amdgpu_find_mm_node(&bo->mem, &offset);
return (bo->mem.bus.base >> PAGE_SHIFT) + mm->start + offset += adev->gmc.aper_base;
(offset >> PAGE_SHIFT); return mm->start + (offset >> PAGE_SHIFT);
} }
/** /**
......
...@@ -43,12 +43,9 @@ void drm_gem_ttm_print_info(struct drm_printer *p, unsigned int indent, ...@@ -43,12 +43,9 @@ void drm_gem_ttm_print_info(struct drm_printer *p, unsigned int indent,
drm_print_bits(p, bo->mem.placement, plname, ARRAY_SIZE(plname)); drm_print_bits(p, bo->mem.placement, plname, ARRAY_SIZE(plname));
drm_printf(p, "\n"); drm_printf(p, "\n");
if (bo->mem.bus.is_iomem) { if (bo->mem.bus.is_iomem)
drm_printf_indent(p, indent, "bus.base=%lx\n",
(unsigned long)bo->mem.bus.base);
drm_printf_indent(p, indent, "bus.offset=%lx\n", drm_printf_indent(p, indent, "bus.offset=%lx\n",
(unsigned long)bo->mem.bus.offset); (unsigned long)bo->mem.bus.offset);
}
} }
EXPORT_SYMBOL(drm_gem_ttm_print_info); EXPORT_SYMBOL(drm_gem_ttm_print_info);
......
...@@ -1042,8 +1042,7 @@ static int bo_driver_io_mem_reserve(struct ttm_bo_device *bdev, ...@@ -1042,8 +1042,7 @@ static int bo_driver_io_mem_reserve(struct ttm_bo_device *bdev,
case TTM_PL_SYSTEM: /* nothing to do */ case TTM_PL_SYSTEM: /* nothing to do */
break; break;
case TTM_PL_VRAM: case TTM_PL_VRAM:
mem->bus.offset = mem->start << PAGE_SHIFT; mem->bus.offset = (mem->start << PAGE_SHIFT) + vmm->vram_base;
mem->bus.base = vmm->vram_base;
mem->bus.is_iomem = true; mem->bus.is_iomem = true;
break; break;
default: default:
......
...@@ -1081,8 +1081,8 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_resource *reg) ...@@ -1081,8 +1081,8 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_resource *reg)
case TTM_PL_TT: case TTM_PL_TT:
#if IS_ENABLED(CONFIG_AGP) #if IS_ENABLED(CONFIG_AGP)
if (drm->agp.bridge) { if (drm->agp.bridge) {
reg->bus.offset = reg->start << PAGE_SHIFT; reg->bus.offset = (reg->start << PAGE_SHIFT) +
reg->bus.base = drm->agp.base; drm->agp.base;
reg->bus.is_iomem = !drm->agp.cma; reg->bus.is_iomem = !drm->agp.cma;
} }
#endif #endif
...@@ -1094,8 +1094,8 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_resource *reg) ...@@ -1094,8 +1094,8 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_resource *reg)
} }
fallthrough; /* tiled memory */ fallthrough; /* tiled memory */
case TTM_PL_VRAM: case TTM_PL_VRAM:
reg->bus.offset = reg->start << PAGE_SHIFT; reg->bus.offset = (reg->start << PAGE_SHIFT) +
reg->bus.base = device->func->resource_addr(device, 1); device->func->resource_addr(device, 1);
reg->bus.is_iomem = true; reg->bus.is_iomem = true;
if (drm->client.mem->oclass >= NVIF_CLASS_MEM_NV50) { if (drm->client.mem->oclass >= NVIF_CLASS_MEM_NV50) {
union { union {
...@@ -1133,7 +1133,6 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_resource *reg) ...@@ -1133,7 +1133,6 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_resource *reg)
goto out; goto out;
} }
reg->bus.base = 0;
reg->bus.offset = handle; reg->bus.offset = handle;
ret = 0; ret = 0;
} }
......
...@@ -378,8 +378,7 @@ nouveau_fbcon_create(struct drm_fb_helper *helper, ...@@ -378,8 +378,7 @@ nouveau_fbcon_create(struct drm_fb_helper *helper,
FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_FILLRECT |
FBINFO_HWACCEL_IMAGEBLIT; FBINFO_HWACCEL_IMAGEBLIT;
info->fbops = &nouveau_fbcon_sw_ops; info->fbops = &nouveau_fbcon_sw_ops;
info->fix.smem_start = nvbo->bo.mem.bus.base + info->fix.smem_start = nvbo->bo.mem.bus.offset;
nvbo->bo.mem.bus.offset;
info->fix.smem_len = nvbo->bo.mem.num_pages << PAGE_SHIFT; info->fix.smem_len = nvbo->bo.mem.num_pages << PAGE_SHIFT;
info->screen_base = nvbo_kmap_obj_iovirtual(nvbo); info->screen_base = nvbo_kmap_obj_iovirtual(nvbo);
......
...@@ -81,13 +81,12 @@ int qxl_ttm_io_mem_reserve(struct ttm_bo_device *bdev, ...@@ -81,13 +81,12 @@ int qxl_ttm_io_mem_reserve(struct ttm_bo_device *bdev,
return 0; return 0;
case TTM_PL_VRAM: case TTM_PL_VRAM:
mem->bus.is_iomem = true; mem->bus.is_iomem = true;
mem->bus.base = qdev->vram_base; mem->bus.offset = (mem->start << PAGE_SHIFT) + qdev->vram_base;
mem->bus.offset = mem->start << PAGE_SHIFT;
break; break;
case TTM_PL_PRIV: case TTM_PL_PRIV:
mem->bus.is_iomem = true; mem->bus.is_iomem = true;
mem->bus.base = qdev->surfaceram_base; mem->bus.offset = (mem->start << PAGE_SHIFT) +
mem->bus.offset = mem->start << PAGE_SHIFT; qdev->surfaceram_base;
break; break;
default: default:
return -EINVAL; return -EINVAL;
......
...@@ -372,8 +372,8 @@ static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso ...@@ -372,8 +372,8 @@ static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso
#if IS_ENABLED(CONFIG_AGP) #if IS_ENABLED(CONFIG_AGP)
if (rdev->flags & RADEON_IS_AGP) { if (rdev->flags & RADEON_IS_AGP) {
/* RADEON_IS_AGP is set only if AGP is active */ /* RADEON_IS_AGP is set only if AGP is active */
mem->bus.offset = mem->start << PAGE_SHIFT; mem->bus.offset = (mem->start << PAGE_SHIFT) +
mem->bus.base = rdev->mc.agp_base; rdev->mc.agp_base;
mem->bus.is_iomem = !rdev->ddev->agp->cant_use_aperture; mem->bus.is_iomem = !rdev->ddev->agp->cant_use_aperture;
} }
#endif #endif
...@@ -383,7 +383,7 @@ static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso ...@@ -383,7 +383,7 @@ static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso
/* check if it's visible */ /* check if it's visible */
if ((mem->bus.offset + bus_size) > rdev->mc.visible_vram_size) if ((mem->bus.offset + bus_size) > rdev->mc.visible_vram_size)
return -EINVAL; return -EINVAL;
mem->bus.base = rdev->mc.aper_base; mem->bus.offset += rdev->mc.aper_base;
mem->bus.is_iomem = true; mem->bus.is_iomem = true;
#ifdef __alpha__ #ifdef __alpha__
/* /*
...@@ -392,12 +392,10 @@ static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso ...@@ -392,12 +392,10 @@ static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso
*/ */
if (mem->placement & TTM_PL_FLAG_WC) if (mem->placement & TTM_PL_FLAG_WC)
mem->bus.addr = mem->bus.addr =
ioremap_wc(mem->bus.base + mem->bus.offset, ioremap_wc(mem->bus.offset, bus_size);
bus_size);
else else
mem->bus.addr = mem->bus.addr =
ioremap(mem->bus.base + mem->bus.offset, ioremap(mem->bus.offset, bus_size);
bus_size);
if (!mem->bus.addr) if (!mem->bus.addr)
return -ENOMEM; return -ENOMEM;
...@@ -407,7 +405,7 @@ static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso ...@@ -407,7 +405,7 @@ static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso
* It then can be used to build PTEs for VRAM * It then can be used to build PTEs for VRAM
* access, as done in ttm_bo_vm_fault(). * access, as done in ttm_bo_vm_fault().
*/ */
mem->bus.base = (mem->bus.base & 0x0ffffffffUL) + mem->bus.offset = (mem->bus.offset & 0x0ffffffffUL) +
rdev->ddev->hose->dense_mem_base; rdev->ddev->hose->dense_mem_base;
#endif #endif
break; break;
......
...@@ -641,7 +641,6 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, ...@@ -641,7 +641,6 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
evict_mem = bo->mem; evict_mem = bo->mem;
evict_mem.mm_node = NULL; evict_mem.mm_node = NULL;
evict_mem.bus.base = 0;
evict_mem.bus.offset = 0; evict_mem.bus.offset = 0;
evict_mem.bus.addr = NULL; evict_mem.bus.addr = NULL;
...@@ -1076,7 +1075,6 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo, ...@@ -1076,7 +1075,6 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
mem.num_pages = bo->num_pages; mem.num_pages = bo->num_pages;
mem.size = mem.num_pages << PAGE_SHIFT; mem.size = mem.num_pages << PAGE_SHIFT;
mem.page_alignment = bo->mem.page_alignment; mem.page_alignment = bo->mem.page_alignment;
mem.bus.base = 0;
mem.bus.offset = 0; mem.bus.offset = 0;
mem.bus.addr = NULL; mem.bus.addr = NULL;
mem.mm_node = NULL; mem.mm_node = NULL;
...@@ -1235,7 +1233,6 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev, ...@@ -1235,7 +1233,6 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
bo->mem.num_pages = bo->num_pages; bo->mem.num_pages = bo->num_pages;
bo->mem.mm_node = NULL; bo->mem.mm_node = NULL;
bo->mem.page_alignment = page_alignment; bo->mem.page_alignment = page_alignment;
bo->mem.bus.base = 0;
bo->mem.bus.offset = 0; bo->mem.bus.offset = 0;
bo->mem.bus.addr = NULL; bo->mem.bus.addr = NULL;
bo->moving = NULL; bo->moving = NULL;
......
...@@ -94,7 +94,7 @@ EXPORT_SYMBOL(ttm_bo_move_ttm); ...@@ -94,7 +94,7 @@ EXPORT_SYMBOL(ttm_bo_move_ttm);
int ttm_mem_io_reserve(struct ttm_bo_device *bdev, int ttm_mem_io_reserve(struct ttm_bo_device *bdev,
struct ttm_resource *mem) struct ttm_resource *mem)
{ {
if (mem->bus.base || mem->bus.offset || mem->bus.addr) if (mem->bus.offset || mem->bus.addr)
return 0; return 0;
mem->bus.is_iomem = false; mem->bus.is_iomem = false;
...@@ -107,13 +107,12 @@ int ttm_mem_io_reserve(struct ttm_bo_device *bdev, ...@@ -107,13 +107,12 @@ int ttm_mem_io_reserve(struct ttm_bo_device *bdev,
void ttm_mem_io_free(struct ttm_bo_device *bdev, void ttm_mem_io_free(struct ttm_bo_device *bdev,
struct ttm_resource *mem) struct ttm_resource *mem)
{ {
if (!mem->bus.base && !mem->bus.offset && !mem->bus.addr) if (!mem->bus.offset && !mem->bus.addr)
return; return;
if (bdev->driver->io_mem_free) if (bdev->driver->io_mem_free)
bdev->driver->io_mem_free(bdev, mem); bdev->driver->io_mem_free(bdev, mem);
mem->bus.base = 0;
mem->bus.offset = 0; mem->bus.offset = 0;
mem->bus.addr = NULL; mem->bus.addr = NULL;
} }
...@@ -136,11 +135,9 @@ static int ttm_resource_ioremap(struct ttm_bo_device *bdev, ...@@ -136,11 +135,9 @@ static int ttm_resource_ioremap(struct ttm_bo_device *bdev,
size_t bus_size = (size_t)mem->num_pages << PAGE_SHIFT; size_t bus_size = (size_t)mem->num_pages << PAGE_SHIFT;
if (mem->placement & TTM_PL_FLAG_WC) if (mem->placement & TTM_PL_FLAG_WC)
addr = ioremap_wc(mem->bus.base + mem->bus.offset, addr = ioremap_wc(mem->bus.offset, bus_size);
bus_size);
else else
addr = ioremap(mem->bus.base + mem->bus.offset, addr = ioremap(mem->bus.offset, bus_size);
bus_size);
if (!addr) { if (!addr) {
ttm_mem_io_free(bdev, mem); ttm_mem_io_free(bdev, mem);
return -ENOMEM; return -ENOMEM;
...@@ -427,12 +424,10 @@ static int ttm_bo_ioremap(struct ttm_buffer_object *bo, ...@@ -427,12 +424,10 @@ static int ttm_bo_ioremap(struct ttm_buffer_object *bo,
} else { } else {
map->bo_kmap_type = ttm_bo_map_iomap; map->bo_kmap_type = ttm_bo_map_iomap;
if (mem->placement & TTM_PL_FLAG_WC) if (mem->placement & TTM_PL_FLAG_WC)
map->virtual = ioremap_wc(bo->mem.bus.base + map->virtual = ioremap_wc(bo->mem.bus.offset + offset,
bo->mem.bus.offset + offset,
size); size);
else else
map->virtual = ioremap(bo->mem.bus.base + map->virtual = ioremap(bo->mem.bus.offset + offset,
bo->mem.bus.offset + offset,
size); size);
} }
return (!map->virtual) ? -ENOMEM : 0; return (!map->virtual) ? -ENOMEM : 0;
......
...@@ -101,8 +101,7 @@ static unsigned long ttm_bo_io_mem_pfn(struct ttm_buffer_object *bo, ...@@ -101,8 +101,7 @@ static unsigned long ttm_bo_io_mem_pfn(struct ttm_buffer_object *bo,
if (bdev->driver->io_mem_pfn) if (bdev->driver->io_mem_pfn)
return bdev->driver->io_mem_pfn(bo, page_offset); return bdev->driver->io_mem_pfn(bo, page_offset);
return ((bo->mem.bus.base + bo->mem.bus.offset) >> PAGE_SHIFT) return (bo->mem.bus.offset >> PAGE_SHIFT) + page_offset;
+ page_offset;
} }
/** /**
......
...@@ -725,8 +725,8 @@ static int vmw_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_resourc ...@@ -725,8 +725,8 @@ static int vmw_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_resourc
case VMW_PL_MOB: case VMW_PL_MOB:
return 0; return 0;
case TTM_PL_VRAM: case TTM_PL_VRAM:
mem->bus.offset = mem->start << PAGE_SHIFT; mem->bus.offset = (mem->start << PAGE_SHIFT) +
mem->bus.base = dev_priv->vram_start; dev_priv->vram_start;
mem->bus.is_iomem = true; mem->bus.is_iomem = true;
break; break;
default: default:
......
...@@ -148,16 +148,14 @@ struct ttm_resource_manager { ...@@ -148,16 +148,14 @@ struct ttm_resource_manager {
* struct ttm_bus_placement * struct ttm_bus_placement
* *
* @addr: mapped virtual address * @addr: mapped virtual address
* @base: bus base address * @offset: physical addr
* @is_iomem: is this io memory ? * @is_iomem: is this io memory ?
* @offset: offset from the base address
* *
* Structure indicating the bus placement of an object. * Structure indicating the bus placement of an object.
*/ */
struct ttm_bus_placement { struct ttm_bus_placement {
void *addr; void *addr;
phys_addr_t base; phys_addr_t offset;
unsigned long offset;
bool is_iomem; bool is_iomem;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment