2014-07-17 01:08:55 +07:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Advanced Micro Devices, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include "kfd_priv.h"
|
|
|
|
|
|
|
|
#define KFD_DRIVER_AUTHOR "AMD Inc. and others"
|
|
|
|
|
|
|
|
#define KFD_DRIVER_DESC "Standalone HSA driver for AMD's GPUs"
|
2015-04-21 19:09:48 +07:00
|
|
|
#define KFD_DRIVER_DATE "20150421"
|
2014-07-17 01:08:55 +07:00
|
|
|
#define KFD_DRIVER_MAJOR 0
|
|
|
|
#define KFD_DRIVER_MINOR 7
|
2015-04-21 19:09:48 +07:00
|
|
|
#define KFD_DRIVER_PATCHLEVEL 2
|
2014-07-17 01:08:55 +07:00
|
|
|
|
|
|
|
static const struct kgd2kfd_calls kgd2kfd = {
|
|
|
|
.exit = kgd2kfd_exit,
|
|
|
|
.probe = kgd2kfd_probe,
|
|
|
|
.device_init = kgd2kfd_device_init,
|
|
|
|
.device_exit = kgd2kfd_device_exit,
|
|
|
|
.interrupt = kgd2kfd_interrupt,
|
|
|
|
.suspend = kgd2kfd_suspend,
|
|
|
|
.resume = kgd2kfd_resume,
|
|
|
|
};
|
|
|
|
|
2014-07-17 04:48:28 +07:00
|
|
|
int sched_policy = KFD_SCHED_POLICY_HWS;
|
|
|
|
module_param(sched_policy, int, 0444);
|
|
|
|
MODULE_PARM_DESC(sched_policy,
|
2015-01-18 18:18:01 +07:00
|
|
|
"Scheduling policy (0 = HWS (Default), 1 = HWS without over-subscription, 2 = Non-HWS (Used for debugging only)");
|
2014-07-17 04:48:28 +07:00
|
|
|
|
2015-01-18 18:18:01 +07:00
|
|
|
int max_num_of_queues_per_device = KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT;
|
|
|
|
module_param(max_num_of_queues_per_device, int, 0444);
|
|
|
|
MODULE_PARM_DESC(max_num_of_queues_per_device,
|
|
|
|
"Maximum number of supported queues per device (1 = Minimum, 4096 = default)");
|
2014-07-17 03:25:31 +07:00
|
|
|
|
2014-12-24 18:30:52 +07:00
|
|
|
int send_sigterm;
|
|
|
|
module_param(send_sigterm, int, 0444);
|
|
|
|
MODULE_PARM_DESC(send_sigterm,
|
|
|
|
"Send sigterm to HSA process on unhandled exception (0 = disable, 1 = enable)");
|
|
|
|
|
drm/amdkfd: Track when module's init is complete
Current dependencies between amdkfd and radeon/amdgpu force the loading
of amdkfd _before_ radeon and/or amdgpu are loaded. When all these kernel
drivers are built as modules, this ordering is enforced by the kernel
built-in mechanism of loading dependent modules.
However, there is no such mechanism in case where all these drivers are
compiled inside the kernel image (not as modules). The current way to
enforce loading of amdkfd before radeon/amdgpu, is to put amdkfd before
radeon/amdgpu in the drm Makefile, but that method is way too fragile.
In addition, there is no kernel mechanism to check whether a kernel
driver that is built inside the kernel image, has already been loaded.
To solve this, this patch adds to kfd_module.c a new static variable,
amdkfd_init_completed, that is set to 1 only when amdkfd's
module initialization function has been completed (successfully).
kgd2kfd_init(), which is the initialization function of the
kgd-->kfd interface, and which is the first function in amdkfd called by
radeon/amdgpu, will return successfully only if amdkfd_init_completed is
equal 1.
If amdkfd_init_completed is not equal to 1, kgd2kfd_init() will
return -EPROBE_DEFER to signal radeon/amdgpu they need to defer
their loading until amdkfd is loaded.
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-02-13 15:14:07 +07:00
|
|
|
static int amdkfd_init_completed;
|
|
|
|
|
2017-08-16 10:00:04 +07:00
|
|
|
int kgd2kfd_init(unsigned int interface_version,
|
|
|
|
const struct kgd2kfd_calls **g2f)
|
2014-07-17 01:08:55 +07:00
|
|
|
{
|
drm/amdkfd: Track when module's init is complete
Current dependencies between amdkfd and radeon/amdgpu force the loading
of amdkfd _before_ radeon and/or amdgpu are loaded. When all these kernel
drivers are built as modules, this ordering is enforced by the kernel
built-in mechanism of loading dependent modules.
However, there is no such mechanism in case where all these drivers are
compiled inside the kernel image (not as modules). The current way to
enforce loading of amdkfd before radeon/amdgpu, is to put amdkfd before
radeon/amdgpu in the drm Makefile, but that method is way too fragile.
In addition, there is no kernel mechanism to check whether a kernel
driver that is built inside the kernel image, has already been loaded.
To solve this, this patch adds to kfd_module.c a new static variable,
amdkfd_init_completed, that is set to 1 only when amdkfd's
module initialization function has been completed (successfully).
kgd2kfd_init(), which is the initialization function of the
kgd-->kfd interface, and which is the first function in amdkfd called by
radeon/amdgpu, will return successfully only if amdkfd_init_completed is
equal 1.
If amdkfd_init_completed is not equal to 1, kgd2kfd_init() will
return -EPROBE_DEFER to signal radeon/amdgpu they need to defer
their loading until amdkfd is loaded.
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-02-13 15:14:07 +07:00
|
|
|
if (!amdkfd_init_completed)
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
|
2014-07-17 01:08:55 +07:00
|
|
|
/*
|
|
|
|
* Only one interface version is supported,
|
|
|
|
* no kfd/kgd version skew allowed.
|
|
|
|
*/
|
|
|
|
if (interface_version != KFD_INTERFACE_VERSION)
|
drm/amdkfd: Track when module's init is complete
Current dependencies between amdkfd and radeon/amdgpu force the loading
of amdkfd _before_ radeon and/or amdgpu are loaded. When all these kernel
drivers are built as modules, this ordering is enforced by the kernel
built-in mechanism of loading dependent modules.
However, there is no such mechanism in case where all these drivers are
compiled inside the kernel image (not as modules). The current way to
enforce loading of amdkfd before radeon/amdgpu, is to put amdkfd before
radeon/amdgpu in the drm Makefile, but that method is way too fragile.
In addition, there is no kernel mechanism to check whether a kernel
driver that is built inside the kernel image, has already been loaded.
To solve this, this patch adds to kfd_module.c a new static variable,
amdkfd_init_completed, that is set to 1 only when amdkfd's
module initialization function has been completed (successfully).
kgd2kfd_init(), which is the initialization function of the
kgd-->kfd interface, and which is the first function in amdkfd called by
radeon/amdgpu, will return successfully only if amdkfd_init_completed is
equal 1.
If amdkfd_init_completed is not equal to 1, kgd2kfd_init() will
return -EPROBE_DEFER to signal radeon/amdgpu they need to defer
their loading until amdkfd is loaded.
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-02-13 15:14:07 +07:00
|
|
|
return -EINVAL;
|
2014-07-17 01:08:55 +07:00
|
|
|
|
|
|
|
*g2f = &kgd2kfd;
|
|
|
|
|
drm/amdkfd: Track when module's init is complete
Current dependencies between amdkfd and radeon/amdgpu force the loading
of amdkfd _before_ radeon and/or amdgpu are loaded. When all these kernel
drivers are built as modules, this ordering is enforced by the kernel
built-in mechanism of loading dependent modules.
However, there is no such mechanism in case where all these drivers are
compiled inside the kernel image (not as modules). The current way to
enforce loading of amdkfd before radeon/amdgpu, is to put amdkfd before
radeon/amdgpu in the drm Makefile, but that method is way too fragile.
In addition, there is no kernel mechanism to check whether a kernel
driver that is built inside the kernel image, has already been loaded.
To solve this, this patch adds to kfd_module.c a new static variable,
amdkfd_init_completed, that is set to 1 only when amdkfd's
module initialization function has been completed (successfully).
kgd2kfd_init(), which is the initialization function of the
kgd-->kfd interface, and which is the first function in amdkfd called by
radeon/amdgpu, will return successfully only if amdkfd_init_completed is
equal 1.
If amdkfd_init_completed is not equal to 1, kgd2kfd_init() will
return -EPROBE_DEFER to signal radeon/amdgpu they need to defer
their loading until amdkfd is loaded.
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-02-13 15:14:07 +07:00
|
|
|
return 0;
|
2014-07-17 01:08:55 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(kgd2kfd_init);
|
|
|
|
|
|
|
|
void kgd2kfd_exit(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init kfd_module_init(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2014-07-17 04:48:28 +07:00
|
|
|
/* Verify module parameters */
|
|
|
|
if ((sched_policy < KFD_SCHED_POLICY_HWS) ||
|
|
|
|
(sched_policy > KFD_SCHED_POLICY_NO_HWS)) {
|
2017-08-16 10:00:05 +07:00
|
|
|
pr_err("sched_policy has invalid value\n");
|
2014-07-17 04:48:28 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-07-17 03:25:31 +07:00
|
|
|
/* Verify module parameters */
|
2015-01-29 15:33:34 +07:00
|
|
|
if ((max_num_of_queues_per_device < 1) ||
|
2015-01-18 18:18:01 +07:00
|
|
|
(max_num_of_queues_per_device >
|
|
|
|
KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) {
|
2017-08-16 10:00:05 +07:00
|
|
|
pr_err("max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n");
|
2014-07-17 03:25:31 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = kfd_pasid_init();
|
|
|
|
if (err < 0)
|
2017-08-16 10:00:07 +07:00
|
|
|
return err;
|
2014-07-17 03:25:31 +07:00
|
|
|
|
2014-07-17 01:08:55 +07:00
|
|
|
err = kfd_chardev_init();
|
|
|
|
if (err < 0)
|
|
|
|
goto err_ioctl;
|
|
|
|
|
2014-07-17 01:22:32 +07:00
|
|
|
err = kfd_topology_init();
|
|
|
|
if (err < 0)
|
|
|
|
goto err_topology;
|
|
|
|
|
2014-07-17 03:25:31 +07:00
|
|
|
kfd_process_create_wq();
|
|
|
|
|
drm/amdkfd: Track when module's init is complete
Current dependencies between amdkfd and radeon/amdgpu force the loading
of amdkfd _before_ radeon and/or amdgpu are loaded. When all these kernel
drivers are built as modules, this ordering is enforced by the kernel
built-in mechanism of loading dependent modules.
However, there is no such mechanism in case where all these drivers are
compiled inside the kernel image (not as modules). The current way to
enforce loading of amdkfd before radeon/amdgpu, is to put amdkfd before
radeon/amdgpu in the drm Makefile, but that method is way too fragile.
In addition, there is no kernel mechanism to check whether a kernel
driver that is built inside the kernel image, has already been loaded.
To solve this, this patch adds to kfd_module.c a new static variable,
amdkfd_init_completed, that is set to 1 only when amdkfd's
module initialization function has been completed (successfully).
kgd2kfd_init(), which is the initialization function of the
kgd-->kfd interface, and which is the first function in amdkfd called by
radeon/amdgpu, will return successfully only if amdkfd_init_completed is
equal 1.
If amdkfd_init_completed is not equal to 1, kgd2kfd_init() will
return -EPROBE_DEFER to signal radeon/amdgpu they need to defer
their loading until amdkfd is loaded.
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-02-13 15:14:07 +07:00
|
|
|
amdkfd_init_completed = 1;
|
|
|
|
|
2014-07-17 01:08:55 +07:00
|
|
|
dev_info(kfd_device, "Initialized module\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2014-07-17 01:22:32 +07:00
|
|
|
err_topology:
|
|
|
|
kfd_chardev_exit();
|
2014-07-17 01:08:55 +07:00
|
|
|
err_ioctl:
|
2014-07-17 03:25:31 +07:00
|
|
|
kfd_pasid_exit();
|
2014-07-17 01:08:55 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit kfd_module_exit(void)
|
|
|
|
{
|
drm/amdkfd: Track when module's init is complete
Current dependencies between amdkfd and radeon/amdgpu force the loading
of amdkfd _before_ radeon and/or amdgpu are loaded. When all these kernel
drivers are built as modules, this ordering is enforced by the kernel
built-in mechanism of loading dependent modules.
However, there is no such mechanism in case where all these drivers are
compiled inside the kernel image (not as modules). The current way to
enforce loading of amdkfd before radeon/amdgpu, is to put amdkfd before
radeon/amdgpu in the drm Makefile, but that method is way too fragile.
In addition, there is no kernel mechanism to check whether a kernel
driver that is built inside the kernel image, has already been loaded.
To solve this, this patch adds to kfd_module.c a new static variable,
amdkfd_init_completed, that is set to 1 only when amdkfd's
module initialization function has been completed (successfully).
kgd2kfd_init(), which is the initialization function of the
kgd-->kfd interface, and which is the first function in amdkfd called by
radeon/amdgpu, will return successfully only if amdkfd_init_completed is
equal 1.
If amdkfd_init_completed is not equal to 1, kgd2kfd_init() will
return -EPROBE_DEFER to signal radeon/amdgpu they need to defer
their loading until amdkfd is loaded.
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-02-13 15:14:07 +07:00
|
|
|
amdkfd_init_completed = 0;
|
|
|
|
|
2014-07-17 03:25:31 +07:00
|
|
|
kfd_process_destroy_wq();
|
2014-07-17 01:22:32 +07:00
|
|
|
kfd_topology_shutdown();
|
2014-07-17 01:08:55 +07:00
|
|
|
kfd_chardev_exit();
|
2014-07-17 03:25:31 +07:00
|
|
|
kfd_pasid_exit();
|
2014-07-17 01:08:55 +07:00
|
|
|
dev_info(kfd_device, "Removed module\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(kfd_module_init);
|
|
|
|
module_exit(kfd_module_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR(KFD_DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(KFD_DRIVER_DESC);
|
|
|
|
MODULE_LICENSE("GPL and additional rights");
|
|
|
|
MODULE_VERSION(__stringify(KFD_DRIVER_MAJOR) "."
|
|
|
|
__stringify(KFD_DRIVER_MINOR) "."
|
|
|
|
__stringify(KFD_DRIVER_PATCHLEVEL));
|