2 * Copyright 2014 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #include <linux/module.h>
24 #include <linux/sched.h>
25 #include <linux/moduleparam.h>
26 #include <linux/device.h>
27 #include <linux/printk.h>
30 #define KFD_DRIVER_AUTHOR "AMD Inc. and others"
32 #define KFD_DRIVER_DESC "Standalone HSA driver for AMD's GPUs"
33 #define KFD_DRIVER_DATE "20150421"
34 #define KFD_DRIVER_MAJOR 0
35 #define KFD_DRIVER_MINOR 7
36 #define KFD_DRIVER_PATCHLEVEL 2
38 static const struct kgd2kfd_calls kgd2kfd = {
40 .probe = kgd2kfd_probe,
41 .device_init = kgd2kfd_device_init,
42 .device_exit = kgd2kfd_device_exit,
43 .interrupt = kgd2kfd_interrupt,
44 .suspend = kgd2kfd_suspend,
45 .resume = kgd2kfd_resume,
46 .schedule_evict_and_restore_process =
47 kgd2kfd_schedule_evict_and_restore_process,
50 int sched_policy = KFD_SCHED_POLICY_HWS;
51 module_param(sched_policy, int, 0444);
52 MODULE_PARM_DESC(sched_policy,
53 "Scheduling policy (0 = HWS (Default), 1 = HWS without over-subscription, 2 = Non-HWS (Used for debugging only)");
55 int hws_max_conc_proc = 8;
56 module_param(hws_max_conc_proc, int, 0444);
57 MODULE_PARM_DESC(hws_max_conc_proc,
58 "Max # processes HWS can execute concurrently when sched_policy=0 (0 = no concurrency, #VMIDs for KFD = Maximum(default))");
61 module_param(cwsr_enable, int, 0444);
62 MODULE_PARM_DESC(cwsr_enable, "CWSR enable (0 = Off, 1 = On (Default))");
64 int max_num_of_queues_per_device = KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT;
65 module_param(max_num_of_queues_per_device, int, 0444);
66 MODULE_PARM_DESC(max_num_of_queues_per_device,
67 "Maximum number of supported queues per device (1 = Minimum, 4096 = default)");
70 module_param(send_sigterm, int, 0444);
71 MODULE_PARM_DESC(send_sigterm,
72 "Send sigterm to HSA process on unhandled exception (0 = disable, 1 = enable)");
75 module_param(ignore_crat, int, 0444);
76 MODULE_PARM_DESC(ignore_crat,
77 "Ignore CRAT table during KFD initialization (0 = use CRAT (default), 1 = ignore CRAT)");
79 static int amdkfd_init_completed;
81 int kgd2kfd_init(unsigned int interface_version,
82 const struct kgd2kfd_calls **g2f)
84 if (!amdkfd_init_completed)
88 * Only one interface version is supported,
89 * no kfd/kgd version skew allowed.
91 if (interface_version != KFD_INTERFACE_VERSION)
98 EXPORT_SYMBOL(kgd2kfd_init);
100 void kgd2kfd_exit(void)
104 static int __init kfd_module_init(void)
108 /* Verify module parameters */
109 if ((sched_policy < KFD_SCHED_POLICY_HWS) ||
110 (sched_policy > KFD_SCHED_POLICY_NO_HWS)) {
111 pr_err("sched_policy has invalid value\n");
115 /* Verify module parameters */
116 if ((max_num_of_queues_per_device < 1) ||
117 (max_num_of_queues_per_device >
118 KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) {
119 pr_err("max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n");
123 err = kfd_chardev_init();
127 err = kfd_topology_init();
131 kfd_process_create_wq();
135 amdkfd_init_completed = 1;
137 dev_info(kfd_device, "Initialized module\n");
147 static void __exit kfd_module_exit(void)
149 amdkfd_init_completed = 0;
152 kfd_process_destroy_wq();
153 kfd_topology_shutdown();
155 pr_info("amdkfd: Removed module\n");
158 module_init(kfd_module_init);
159 module_exit(kfd_module_exit);
161 MODULE_AUTHOR(KFD_DRIVER_AUTHOR);
162 MODULE_DESCRIPTION(KFD_DRIVER_DESC);
163 MODULE_LICENSE("GPL and additional rights");
164 MODULE_VERSION(__stringify(KFD_DRIVER_MAJOR) "."
165 __stringify(KFD_DRIVER_MINOR) "."
166 __stringify(KFD_DRIVER_PATCHLEVEL));