Skip to content

Commit

Permalink
amdkfd: Add basic modules to amdkfd
Browse files Browse the repository at this point in the history
This patch adds the process module and three helper modules:

- kfd_process, which handles process which open /dev/kfd

- kfd_doorbell, which provides helper functions for doorbell allocation,
  release and mapping to userspace

- kfd_pasid, which provides helper functions for pasid allocation and release

- kfd_aperture, which provides helper functions for managing the LDS, Local GPU
  memory and Scratch memory apertures of the process

This patch only contains the basic kfd_process module, which doesn't contain
the reference to the queue scheduler. This was done to allow easier code review.

Also, this patch doesn't contain the calls to the IOMMU driver for binding the
pasid to the device. Again, this was done to allow easier code review

The kfd_process object is created when a process opens /dev/kfd and is closed
when the mm_struct of that process is teared-down.

v3:

Removed kfd_vidmem.c file
Replaced direct mmput call to mmu_notifier release
Removed typedefs
Moved bool field to end of the structure
Added new kernel params for gart usage limitation
Added initialization of sa manager
Fixed debug messages
Remove support for LDS in 32 bit
Changed code to support mmap of doorbell pages from userspace
Added documentation for apertures

v4: Replaced RCU by SRCU for kfd_process list management

v5:

Move amdkfd from drm/radeon/ to drm/amd/
Rename kfd_aperture.c to kfd_flat_memory.c
Protect against multiple init calls
MQD size is H/W dependent so moved it to device info structure
Rename kfd_mem_obj structure's members
Use delayed function for process tear-down

Signed-off-by: Oded Gabbay <oded.gabbay@amd.com>
  • Loading branch information
Oded Gabbay committed Jul 16, 2014
1 parent 5b5c4e4 commit 19f6d2a
Show file tree
Hide file tree
Showing 9 changed files with 1,349 additions and 10 deletions.
4 changes: 3 additions & 1 deletion drivers/gpu/drm/amd/amdkfd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

ccflags-y := -Iinclude/drm -Idrivers/gpu/drm/amd/include/

amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o
amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \
kfd_pasid.o kfd_doorbell.o kfd_flat_memory.o \
kfd_process.o

obj-$(CONFIG_HSA_AMD) += amdkfd.o
31 changes: 29 additions & 2 deletions drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

static long kfd_ioctl(struct file *, unsigned int, unsigned long);
static int kfd_open(struct inode *, struct file *);
static int kfd_mmap(struct file *, struct vm_area_struct *);

static const char kfd_dev_name[] = "kfd";

Expand All @@ -46,6 +47,7 @@ static const struct file_operations kfd_fops = {
.unlocked_ioctl = kfd_ioctl,
.compat_ioctl = kfd_ioctl,
.open = kfd_open,
.mmap = kfd_mmap,
};

static int kfd_char_dev_major = -1;
Expand Down Expand Up @@ -98,9 +100,22 @@ struct device *kfd_chardev(void)

static int kfd_open(struct inode *inode, struct file *filep)
{
struct kfd_process *process;

if (iminor(inode) != 0)
return -ENODEV;

process = kfd_create_process(current);
if (IS_ERR(process))
return PTR_ERR(process);

process->is_32bit_user_mode = is_compat_task();

dev_dbg(kfd_device, "process %d opened, compat mode (32 bit) - %d\n",
process->pasid, process->is_32bit_user_mode);

kfd_init_apertures(process);

return 0;
}

Expand Down Expand Up @@ -156,8 +171,9 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
"ioctl cmd 0x%x (#%d), arg 0x%lx\n",
cmd, _IOC_NR(cmd), arg);

/* TODO: add function that retrieves process */
process = NULL;
process = kfd_get_process(current);
if (IS_ERR(process))
return PTR_ERR(process);

switch (cmd) {
case KFD_IOC_GET_VERSION:
Expand Down Expand Up @@ -208,3 +224,14 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)

return err;
}

static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
{
struct kfd_process *process;

process = kfd_get_process(current);
if (IS_ERR(process))
return PTR_ERR(process);

return kfd_doorbell_mmap(process, vma);
}
46 changes: 40 additions & 6 deletions drivers/gpu/drm/amd/amdkfd/kfd_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
#include <linux/slab.h>
#include "kfd_priv.h"

#define MQD_SIZE_ALIGNED 768

static const struct kfd_device_info kaveri_device_info = {
.max_pasid_bits = 16,
.mqd_size_aligned = MQD_SIZE_ALIGNED
};

struct kfd_deviceid {
Expand Down Expand Up @@ -92,30 +95,61 @@ struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd, struct pci_dev *pdev)
kfd->kgd = kgd;
kfd->device_info = device_info;
kfd->pdev = pdev;
kfd->init_complete = false;

return kfd;
}

bool kgd2kfd_device_init(struct kfd_dev *kfd,
const struct kgd2kfd_shared_resources *gpu_resources)
{
unsigned int size;

kfd->shared_resources = *gpu_resources;

if (kfd_topology_add_device(kfd) != 0)
return false;
/* calculate max size of mqds needed for queues */
size = max_num_of_processes *
max_num_of_queues_per_process *
kfd->device_info->mqd_size_aligned;

/* add another 512KB for all other allocations on gart */
size += 512 * 1024;

if (kfd2kgd->init_sa_manager(kfd->kgd, size)) {
dev_err(kfd_device,
"Error initializing sa manager for device (%x:%x)\n",
kfd->pdev->vendor, kfd->pdev->device);
goto out;
}

kfd_doorbell_init(kfd);

if (kfd_topology_add_device(kfd) != 0) {
dev_err(kfd_device,
"Error adding device (%x:%x) to topology\n",
kfd->pdev->vendor, kfd->pdev->device);
goto kfd_topology_add_device_error;
}


kfd->init_complete = true;
dev_info(kfd_device, "added device (%x:%x)\n", kfd->pdev->vendor,
kfd->pdev->device);

return true;
goto out;

kfd_topology_add_device_error:
kfd2kgd->fini_sa_manager(kfd->kgd);
dev_err(kfd_device,
"device (%x:%x) NOT added due to errors\n",
kfd->pdev->vendor, kfd->pdev->device);
out:
return kfd->init_complete;
}

void kgd2kfd_device_exit(struct kfd_dev *kfd)
{
int err = kfd_topology_remove_device(kfd);

BUG_ON(err != 0);
kfd_topology_remove_device(kfd);

kfree(kfd);
}
Expand Down
Loading

0 comments on commit 19f6d2a

Please sign in to comment.