2009-06-05 19:42:42 +07:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Advanced Micro Devices, Inc.
|
|
|
|
* Copyright 2008 Red Hat Inc.
|
|
|
|
* Copyright 2009 Jerome Glisse.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors: Dave Airlie
|
|
|
|
* Alex Deucher
|
|
|
|
* Jerome Glisse
|
|
|
|
*/
|
|
|
|
#ifndef __RADEON_OBJECT_H__
|
|
|
|
#define __RADEON_OBJECT_H__
|
|
|
|
|
2009-11-20 20:29:23 +07:00
|
|
|
#include <drm/radeon_drm.h>
|
|
|
|
#include "radeon.h"
|
2009-06-05 19:42:42 +07:00
|
|
|
|
2009-11-20 20:29:23 +07:00
|
|
|
/**
|
|
|
|
* radeon_mem_type_to_domain - return domain corresponding to mem_type
|
|
|
|
* @mem_type: ttm memory type
|
|
|
|
*
|
|
|
|
* Returns corresponding domain of the ttm mem_type
|
|
|
|
*/
|
|
|
|
static inline unsigned radeon_mem_type_to_domain(u32 mem_type)
|
|
|
|
{
|
|
|
|
switch (mem_type) {
|
|
|
|
case TTM_PL_VRAM:
|
|
|
|
return RADEON_GEM_DOMAIN_VRAM;
|
|
|
|
case TTM_PL_TT:
|
|
|
|
return RADEON_GEM_DOMAIN_GTT;
|
|
|
|
case TTM_PL_SYSTEM:
|
|
|
|
return RADEON_GEM_DOMAIN_CPU;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-27 18:48:23 +07:00
|
|
|
/**
|
|
|
|
* radeon_bo_reserve - reserve bo
|
|
|
|
* @bo: bo structure
|
|
|
|
* @no_intr: don't return -ERESTARTSYS on pending signal
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by
|
|
|
|
* a signal. Release all buffer reservations and return to user-space.
|
|
|
|
*/
|
|
|
|
static inline int radeon_bo_reserve(struct radeon_bo *bo, bool no_intr)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2016-04-06 16:12:03 +07:00
|
|
|
r = ttm_bo_reserve(&bo->tbo, !no_intr, false, NULL);
|
2013-06-27 18:48:23 +07:00
|
|
|
if (unlikely(r != 0)) {
|
|
|
|
if (r != -ERESTARTSYS)
|
|
|
|
dev_err(bo->rdev->dev, "%p reserve failed\n", bo);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-11-20 20:29:23 +07:00
|
|
|
|
|
|
|
static inline void radeon_bo_unreserve(struct radeon_bo *bo)
|
|
|
|
{
|
|
|
|
ttm_bo_unreserve(&bo->tbo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* radeon_bo_gpu_offset - return GPU offset of bo
|
|
|
|
* @bo: radeon object for which we query the offset
|
|
|
|
*
|
|
|
|
* Returns current GPU offset of the object.
|
|
|
|
*
|
|
|
|
* Note: object should either be pinned or reserved when calling this
|
2011-03-31 08:57:33 +07:00
|
|
|
* function, it might be useful to add check for this for debugging.
|
2009-11-20 20:29:23 +07:00
|
|
|
*/
|
|
|
|
static inline u64 radeon_bo_gpu_offset(struct radeon_bo *bo)
|
|
|
|
{
|
|
|
|
return bo->tbo.offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long radeon_bo_size(struct radeon_bo *bo)
|
|
|
|
{
|
|
|
|
return bo->tbo.num_pages << PAGE_SHIFT;
|
|
|
|
}
|
|
|
|
|
drm/radeon: GPU virtual memory support v22
Virtual address space are per drm client (opener of /dev/drm).
Client are in charge of virtual address space, they need to
map bo into it by calling DRM_RADEON_GEM_VA ioctl.
First 16M of virtual address space is reserved by the kernel.
Once using 2 level page table we should be able to have a small
vram memory footprint for each pt (there would be one pt for all
gart, one for all vram and then one first level for each virtual
address space).
Plan include using the sub allocator for a common vm page table
area and using memcpy to copy vm page table in & out. Or use
a gart object and copy things in & out using dma.
v2: agd5f fixes:
- Add vram base offset for vram pages. The GPU physical address of a
vram page is FB_OFFSET + page offset. FB_OFFSET is 0 on discrete
cards and the physical bus address of the stolen memory on
integrated chips.
- VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR covers all vmid's >= 1
v3: agd5f:
- integrate with the semaphore/multi-ring stuff
v4:
- rebase on top ttm dma & multi-ring stuff
- userspace is now in charge of the address space
- no more specific cs vm ioctl, instead cs ioctl has a new
chunk
v5:
- properly handle mem == NULL case from move_notify callback
- fix the vm cleanup path
v6:
- fix update of page table to only happen on valid mem placement
v7:
- add tlb flush for each vm context
- add flags to define mapping property (readable, writeable, snooped)
- make ring id implicit from ib->fence->ring, up to each asic callback
to then do ring specific scheduling if vm ib scheduling function
v8:
- add query for ib limit and kernel reserved virtual space
- rename vm->size to max_pfn (maximum number of page)
- update gem_va ioctl to also allow unmap operation
- bump kernel version to allow userspace to query for vm support
v9:
- rebuild page table only when bind and incrementaly depending
on bo referenced by cs and that have been moved
- allow virtual address space to grow
- use sa allocator for vram page table
- return invalid when querying vm limit on non cayman GPU
- dump vm fault register on lockup
v10: agd5f:
- Move the vm schedule_ib callback to a standalone function, remove
the callback and use the existing ib_execute callback for VM IBs.
v11:
- rebase on top of lastest Linus
v12: agd5f:
- remove spurious backslash
- set IB vm_id to 0 in radeon_ib_get()
v13: agd5f:
- fix handling of RADEON_CHUNK_ID_FLAGS
v14:
- fix va destruction
- fix suspend resume
- forbid bo to have several different va in same vm
v15:
- rebase
v16:
- cleanup left over of vm init/fini
v17: agd5f:
- cs checker
v18: agd5f:
- reworks the CS ioctl to better support multiple rings and
VM. Rather than adding a new chunk id for VM, just re-use the
IB chunk id and add a new flags for VM mode. Also define additional
dwords for the flags chunk id to define the what ring we want to use
(gfx, compute, uvd, etc.) and the priority.
v19:
- fix cs fini in weird case of no ib
- semi working flush fix for ni
- rebase on top of sa allocator changes
v20: agd5f:
- further CS ioctl cleanups from Christian's comments
v21: agd5f:
- integrate CS checker improvements
v22: agd5f:
- final cleanups for release, only allow VM CS on cayman
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2012-01-06 10:11:05 +07:00
|
|
|
static inline unsigned radeon_bo_ngpu_pages(struct radeon_bo *bo)
|
|
|
|
{
|
|
|
|
return (bo->tbo.num_pages << PAGE_SHIFT) / RADEON_GPU_PAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned radeon_bo_gpu_page_alignment(struct radeon_bo *bo)
|
|
|
|
{
|
|
|
|
return (bo->tbo.mem.page_alignment << PAGE_SHIFT) / RADEON_GPU_PAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
2009-11-20 20:29:23 +07:00
|
|
|
/**
|
|
|
|
* radeon_bo_mmap_offset - return mmap offset of bo
|
|
|
|
* @bo: radeon object for which we query the offset
|
|
|
|
*
|
|
|
|
* Returns mmap offset of the object.
|
2009-06-05 19:42:42 +07:00
|
|
|
*/
|
2009-11-20 20:29:23 +07:00
|
|
|
static inline u64 radeon_bo_mmap_offset(struct radeon_bo *bo)
|
|
|
|
{
|
2013-07-25 02:08:53 +07:00
|
|
|
return drm_vma_node_offset_addr(&bo->tbo.vma_node);
|
2009-11-20 20:29:23 +07:00
|
|
|
}
|
|
|
|
|
2011-10-14 06:08:47 +07:00
|
|
|
extern int radeon_bo_wait(struct radeon_bo *bo, u32 *mem_type,
|
2011-10-27 23:15:10 +07:00
|
|
|
bool no_wait);
|
2009-11-20 20:29:23 +07:00
|
|
|
|
|
|
|
extern int radeon_bo_create(struct radeon_device *rdev,
|
2012-05-11 05:33:13 +07:00
|
|
|
unsigned long size, int byte_align,
|
2014-07-17 17:01:08 +07:00
|
|
|
bool kernel, u32 domain, u32 flags,
|
2012-05-11 05:33:13 +07:00
|
|
|
struct sg_table *sg,
|
2014-09-18 19:11:56 +07:00
|
|
|
struct reservation_object *resv,
|
2012-05-11 05:33:13 +07:00
|
|
|
struct radeon_bo **bo_ptr);
|
2009-11-20 20:29:23 +07:00
|
|
|
extern int radeon_bo_kmap(struct radeon_bo *bo, void **ptr);
|
|
|
|
extern void radeon_bo_kunmap(struct radeon_bo *bo);
|
2014-07-31 02:04:56 +07:00
|
|
|
extern struct radeon_bo *radeon_bo_ref(struct radeon_bo *bo);
|
2009-11-20 20:29:23 +07:00
|
|
|
extern void radeon_bo_unref(struct radeon_bo **bo);
|
|
|
|
extern int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr);
|
2012-03-14 23:12:41 +07:00
|
|
|
extern int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain,
|
|
|
|
u64 max_offset, u64 *gpu_addr);
|
2009-11-20 20:29:23 +07:00
|
|
|
extern int radeon_bo_unpin(struct radeon_bo *bo);
|
|
|
|
extern int radeon_bo_evict_vram(struct radeon_device *rdev);
|
|
|
|
extern void radeon_bo_force_delete(struct radeon_device *rdev);
|
|
|
|
extern int radeon_bo_init(struct radeon_device *rdev);
|
|
|
|
extern void radeon_bo_fini(struct radeon_device *rdev);
|
2014-03-02 06:56:22 +07:00
|
|
|
extern int radeon_bo_list_validate(struct radeon_device *rdev,
|
|
|
|
struct ww_acquire_ctx *ticket,
|
2013-06-27 18:48:17 +07:00
|
|
|
struct list_head *head, int ring);
|
2009-11-20 20:29:23 +07:00
|
|
|
extern int radeon_bo_set_tiling_flags(struct radeon_bo *bo,
|
|
|
|
u32 tiling_flags, u32 pitch);
|
|
|
|
extern void radeon_bo_get_tiling_flags(struct radeon_bo *bo,
|
|
|
|
u32 *tiling_flags, u32 *pitch);
|
|
|
|
extern int radeon_bo_check_tiling(struct radeon_bo *bo, bool has_moved,
|
|
|
|
bool force_drop);
|
|
|
|
extern void radeon_bo_move_notify(struct ttm_buffer_object *bo,
|
2016-12-15 23:23:49 +07:00
|
|
|
bool evict,
|
2014-03-02 06:56:18 +07:00
|
|
|
struct ttm_mem_reg *new_mem);
|
2010-04-09 19:39:24 +07:00
|
|
|
extern int radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo);
|
2009-12-09 11:15:38 +07:00
|
|
|
extern int radeon_bo_get_surface_reg(struct radeon_bo *bo);
|
2014-11-19 20:01:23 +07:00
|
|
|
extern void radeon_bo_fence(struct radeon_bo *bo, struct radeon_fence *fence,
|
|
|
|
bool shared);
|
drm/radeon: introduce a sub allocator and convert ib pool to it v4
Somewhat specializaed sub-allocator designed to perform sub-allocation
for command buffer not only for current cs ioctl but for future command
submission ioctl as well. Patch also convert current ib pool to use
the sub allocator. Idea is that ib poll buffer can be share with other
command buffer submission not having 64K granularity.
v2 Harmonize pool handling and add suspend/resume callback to pin/unpin
sa bo (tested on rv280, rv370, r420, rv515, rv610, rv710, redwood, cayman,
rs480, rs690, rs880)
v3 Simplify allocator
v4 Fix radeon_ib_get error path to properly free fence
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2011-11-15 23:48:34 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* sub allocation
|
|
|
|
*/
|
2012-05-09 20:34:49 +07:00
|
|
|
|
|
|
|
static inline uint64_t radeon_sa_bo_gpu_addr(struct radeon_sa_bo *sa_bo)
|
|
|
|
{
|
2012-05-09 20:34:52 +07:00
|
|
|
return sa_bo->manager->gpu_addr + sa_bo->soffset;
|
2012-05-09 20:34:49 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void * radeon_sa_bo_cpu_addr(struct radeon_sa_bo *sa_bo)
|
|
|
|
{
|
2012-05-09 20:34:52 +07:00
|
|
|
return sa_bo->manager->cpu_ptr + sa_bo->soffset;
|
2012-05-09 20:34:49 +07:00
|
|
|
}
|
|
|
|
|
drm/radeon: introduce a sub allocator and convert ib pool to it v4
Somewhat specializaed sub-allocator designed to perform sub-allocation
for command buffer not only for current cs ioctl but for future command
submission ioctl as well. Patch also convert current ib pool to use
the sub allocator. Idea is that ib poll buffer can be share with other
command buffer submission not having 64K granularity.
v2 Harmonize pool handling and add suspend/resume callback to pin/unpin
sa bo (tested on rv280, rv370, r420, rv515, rv610, rv710, redwood, cayman,
rs480, rs690, rs880)
v3 Simplify allocator
v4 Fix radeon_ib_get error path to properly free fence
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2011-11-15 23:48:34 +07:00
|
|
|
extern int radeon_sa_bo_manager_init(struct radeon_device *rdev,
|
|
|
|
struct radeon_sa_manager *sa_manager,
|
2014-07-17 17:01:08 +07:00
|
|
|
unsigned size, u32 align, u32 domain,
|
|
|
|
u32 flags);
|
drm/radeon: introduce a sub allocator and convert ib pool to it v4
Somewhat specializaed sub-allocator designed to perform sub-allocation
for command buffer not only for current cs ioctl but for future command
submission ioctl as well. Patch also convert current ib pool to use
the sub allocator. Idea is that ib poll buffer can be share with other
command buffer submission not having 64K granularity.
v2 Harmonize pool handling and add suspend/resume callback to pin/unpin
sa bo (tested on rv280, rv370, r420, rv515, rv610, rv710, redwood, cayman,
rs480, rs690, rs880)
v3 Simplify allocator
v4 Fix radeon_ib_get error path to properly free fence
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2011-11-15 23:48:34 +07:00
|
|
|
extern void radeon_sa_bo_manager_fini(struct radeon_device *rdev,
|
|
|
|
struct radeon_sa_manager *sa_manager);
|
|
|
|
extern int radeon_sa_bo_manager_start(struct radeon_device *rdev,
|
|
|
|
struct radeon_sa_manager *sa_manager);
|
|
|
|
extern int radeon_sa_bo_manager_suspend(struct radeon_device *rdev,
|
|
|
|
struct radeon_sa_manager *sa_manager);
|
|
|
|
extern int radeon_sa_bo_new(struct radeon_device *rdev,
|
|
|
|
struct radeon_sa_manager *sa_manager,
|
2012-05-09 20:34:53 +07:00
|
|
|
struct radeon_sa_bo **sa_bo,
|
2014-02-21 03:48:00 +07:00
|
|
|
unsigned size, unsigned align);
|
drm/radeon: introduce a sub allocator and convert ib pool to it v4
Somewhat specializaed sub-allocator designed to perform sub-allocation
for command buffer not only for current cs ioctl but for future command
submission ioctl as well. Patch also convert current ib pool to use
the sub allocator. Idea is that ib poll buffer can be share with other
command buffer submission not having 64K granularity.
v2 Harmonize pool handling and add suspend/resume callback to pin/unpin
sa bo (tested on rv280, rv370, r420, rv515, rv610, rv710, redwood, cayman,
rs480, rs690, rs880)
v3 Simplify allocator
v4 Fix radeon_ib_get error path to properly free fence
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2011-11-15 23:48:34 +07:00
|
|
|
extern void radeon_sa_bo_free(struct radeon_device *rdev,
|
2012-05-09 20:34:54 +07:00
|
|
|
struct radeon_sa_bo **sa_bo,
|
|
|
|
struct radeon_fence *fence);
|
2012-05-09 20:34:51 +07:00
|
|
|
#if defined(CONFIG_DEBUG_FS)
|
|
|
|
extern void radeon_sa_bo_dump_debug_info(struct radeon_sa_manager *sa_manager,
|
|
|
|
struct seq_file *m);
|
|
|
|
#endif
|
|
|
|
|
drm/radeon: introduce a sub allocator and convert ib pool to it v4
Somewhat specializaed sub-allocator designed to perform sub-allocation
for command buffer not only for current cs ioctl but for future command
submission ioctl as well. Patch also convert current ib pool to use
the sub allocator. Idea is that ib poll buffer can be share with other
command buffer submission not having 64K granularity.
v2 Harmonize pool handling and add suspend/resume callback to pin/unpin
sa bo (tested on rv280, rv370, r420, rv515, rv610, rv710, redwood, cayman,
rs480, rs690, rs880)
v3 Simplify allocator
v4 Fix radeon_ib_get error path to properly free fence
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2011-11-15 23:48:34 +07:00
|
|
|
|
2009-06-05 19:42:42 +07:00
|
|
|
#endif
|