| .. | .. |
|---|
| 20 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
|---|
| 21 | 21 | */ |
|---|
| 22 | 22 | |
|---|
| 23 | | -#include <linux/module.h> |
|---|
| 24 | 23 | #include <linux/sched.h> |
|---|
| 25 | | -#include <linux/moduleparam.h> |
|---|
| 26 | 24 | #include <linux/device.h> |
|---|
| 27 | | -#include <linux/printk.h> |
|---|
| 28 | 25 | #include "kfd_priv.h" |
|---|
| 26 | +#include "amdgpu_amdkfd.h" |
|---|
| 29 | 27 | |
|---|
| 30 | | -#define KFD_DRIVER_AUTHOR "AMD Inc. and others" |
|---|
| 31 | | - |
|---|
| 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 |
|---|
| 37 | | - |
|---|
| 38 | | -static const struct kgd2kfd_calls kgd2kfd = { |
|---|
| 39 | | - .exit = kgd2kfd_exit, |
|---|
| 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 | | - .quiesce_mm = kgd2kfd_quiesce_mm, |
|---|
| 47 | | - .resume_mm = kgd2kfd_resume_mm, |
|---|
| 48 | | - .schedule_evict_and_restore_process = |
|---|
| 49 | | - kgd2kfd_schedule_evict_and_restore_process, |
|---|
| 50 | | - .pre_reset = kgd2kfd_pre_reset, |
|---|
| 51 | | - .post_reset = kgd2kfd_post_reset, |
|---|
| 52 | | -}; |
|---|
| 53 | | - |
|---|
| 54 | | -int sched_policy = KFD_SCHED_POLICY_HWS; |
|---|
| 55 | | -module_param(sched_policy, int, 0444); |
|---|
| 56 | | -MODULE_PARM_DESC(sched_policy, |
|---|
| 57 | | - "Scheduling policy (0 = HWS (Default), 1 = HWS without over-subscription, 2 = Non-HWS (Used for debugging only)"); |
|---|
| 58 | | - |
|---|
| 59 | | -int hws_max_conc_proc = 8; |
|---|
| 60 | | -module_param(hws_max_conc_proc, int, 0444); |
|---|
| 61 | | -MODULE_PARM_DESC(hws_max_conc_proc, |
|---|
| 62 | | - "Max # processes HWS can execute concurrently when sched_policy=0 (0 = no concurrency, #VMIDs for KFD = Maximum(default))"); |
|---|
| 63 | | - |
|---|
| 64 | | -int cwsr_enable = 1; |
|---|
| 65 | | -module_param(cwsr_enable, int, 0444); |
|---|
| 66 | | -MODULE_PARM_DESC(cwsr_enable, "CWSR enable (0 = off, 1 = on (default))"); |
|---|
| 67 | | - |
|---|
| 68 | | -int max_num_of_queues_per_device = KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT; |
|---|
| 69 | | -module_param(max_num_of_queues_per_device, int, 0444); |
|---|
| 70 | | -MODULE_PARM_DESC(max_num_of_queues_per_device, |
|---|
| 71 | | - "Maximum number of supported queues per device (1 = Minimum, 4096 = default)"); |
|---|
| 72 | | - |
|---|
| 73 | | -int send_sigterm; |
|---|
| 74 | | -module_param(send_sigterm, int, 0444); |
|---|
| 75 | | -MODULE_PARM_DESC(send_sigterm, |
|---|
| 76 | | - "Send sigterm to HSA process on unhandled exception (0 = disable, 1 = enable)"); |
|---|
| 77 | | - |
|---|
| 78 | | -int debug_largebar; |
|---|
| 79 | | -module_param(debug_largebar, int, 0444); |
|---|
| 80 | | -MODULE_PARM_DESC(debug_largebar, |
|---|
| 81 | | - "Debug large-bar flag used to simulate large-bar capability on non-large bar machine (0 = disable, 1 = enable)"); |
|---|
| 82 | | - |
|---|
| 83 | | -int ignore_crat; |
|---|
| 84 | | -module_param(ignore_crat, int, 0444); |
|---|
| 85 | | -MODULE_PARM_DESC(ignore_crat, |
|---|
| 86 | | - "Ignore CRAT table during KFD initialization (0 = use CRAT (default), 1 = ignore CRAT)"); |
|---|
| 87 | | - |
|---|
| 88 | | -int noretry; |
|---|
| 89 | | -module_param(noretry, int, 0644); |
|---|
| 90 | | -MODULE_PARM_DESC(noretry, |
|---|
| 91 | | - "Set sh_mem_config.retry_disable on GFXv9+ dGPUs (0 = retry enabled (default), 1 = retry disabled)"); |
|---|
| 92 | | - |
|---|
| 93 | | -int halt_if_hws_hang; |
|---|
| 94 | | -module_param(halt_if_hws_hang, int, 0644); |
|---|
| 95 | | -MODULE_PARM_DESC(halt_if_hws_hang, "Halt if HWS hang is detected (0 = off (default), 1 = on)"); |
|---|
| 96 | | - |
|---|
| 97 | | - |
|---|
| 98 | | -static int amdkfd_init_completed; |
|---|
| 99 | | - |
|---|
| 100 | | - |
|---|
| 101 | | -int kgd2kfd_init(unsigned int interface_version, |
|---|
| 102 | | - const struct kgd2kfd_calls **g2f) |
|---|
| 103 | | -{ |
|---|
| 104 | | - if (!amdkfd_init_completed) |
|---|
| 105 | | - return -EPROBE_DEFER; |
|---|
| 106 | | - |
|---|
| 107 | | - /* |
|---|
| 108 | | - * Only one interface version is supported, |
|---|
| 109 | | - * no kfd/kgd version skew allowed. |
|---|
| 110 | | - */ |
|---|
| 111 | | - if (interface_version != KFD_INTERFACE_VERSION) |
|---|
| 112 | | - return -EINVAL; |
|---|
| 113 | | - |
|---|
| 114 | | - *g2f = &kgd2kfd; |
|---|
| 115 | | - |
|---|
| 116 | | - return 0; |
|---|
| 117 | | -} |
|---|
| 118 | | -EXPORT_SYMBOL(kgd2kfd_init); |
|---|
| 119 | | - |
|---|
| 120 | | -void kgd2kfd_exit(void) |
|---|
| 121 | | -{ |
|---|
| 122 | | -} |
|---|
| 123 | | - |
|---|
| 124 | | -static int __init kfd_module_init(void) |
|---|
| 28 | +static int kfd_init(void) |
|---|
| 125 | 29 | { |
|---|
| 126 | 30 | int err; |
|---|
| 127 | 31 | |
|---|
| .. | .. |
|---|
| 129 | 33 | if ((sched_policy < KFD_SCHED_POLICY_HWS) || |
|---|
| 130 | 34 | (sched_policy > KFD_SCHED_POLICY_NO_HWS)) { |
|---|
| 131 | 35 | pr_err("sched_policy has invalid value\n"); |
|---|
| 132 | | - return -1; |
|---|
| 36 | + return -EINVAL; |
|---|
| 133 | 37 | } |
|---|
| 134 | 38 | |
|---|
| 135 | 39 | /* Verify module parameters */ |
|---|
| .. | .. |
|---|
| 137 | 41 | (max_num_of_queues_per_device > |
|---|
| 138 | 42 | KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) { |
|---|
| 139 | 43 | pr_err("max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n"); |
|---|
| 140 | | - return -1; |
|---|
| 44 | + return -EINVAL; |
|---|
| 141 | 45 | } |
|---|
| 142 | 46 | |
|---|
| 143 | 47 | err = kfd_chardev_init(); |
|---|
| .. | .. |
|---|
| 152 | 56 | if (err < 0) |
|---|
| 153 | 57 | goto err_create_wq; |
|---|
| 154 | 58 | |
|---|
| 59 | + /* Ignore the return value, so that we can continue |
|---|
| 60 | + * to init the KFD, even if procfs isn't craated |
|---|
| 61 | + */ |
|---|
| 62 | + kfd_procfs_init(); |
|---|
| 63 | + |
|---|
| 155 | 64 | kfd_debugfs_init(); |
|---|
| 156 | | - |
|---|
| 157 | | - amdkfd_init_completed = 1; |
|---|
| 158 | | - |
|---|
| 159 | | - dev_info(kfd_device, "Initialized module\n"); |
|---|
| 160 | 65 | |
|---|
| 161 | 66 | return 0; |
|---|
| 162 | 67 | |
|---|
| .. | .. |
|---|
| 165 | 70 | err_topology: |
|---|
| 166 | 71 | kfd_chardev_exit(); |
|---|
| 167 | 72 | err_ioctl: |
|---|
| 73 | + pr_err("KFD is disabled due to module initialization failure\n"); |
|---|
| 168 | 74 | return err; |
|---|
| 169 | 75 | } |
|---|
| 170 | 76 | |
|---|
| 171 | | -static void __exit kfd_module_exit(void) |
|---|
| 77 | +static void kfd_exit(void) |
|---|
| 172 | 78 | { |
|---|
| 173 | | - amdkfd_init_completed = 0; |
|---|
| 174 | | - |
|---|
| 175 | 79 | kfd_debugfs_fini(); |
|---|
| 176 | 80 | kfd_process_destroy_wq(); |
|---|
| 81 | + kfd_procfs_shutdown(); |
|---|
| 177 | 82 | kfd_topology_shutdown(); |
|---|
| 178 | 83 | kfd_chardev_exit(); |
|---|
| 179 | | - pr_info("amdkfd: Removed module\n"); |
|---|
| 180 | 84 | } |
|---|
| 181 | 85 | |
|---|
| 182 | | -module_init(kfd_module_init); |
|---|
| 183 | | -module_exit(kfd_module_exit); |
|---|
| 86 | +int kgd2kfd_init(void) |
|---|
| 87 | +{ |
|---|
| 88 | + return kfd_init(); |
|---|
| 89 | +} |
|---|
| 184 | 90 | |
|---|
| 185 | | -MODULE_AUTHOR(KFD_DRIVER_AUTHOR); |
|---|
| 186 | | -MODULE_DESCRIPTION(KFD_DRIVER_DESC); |
|---|
| 187 | | -MODULE_LICENSE("GPL and additional rights"); |
|---|
| 188 | | -MODULE_VERSION(__stringify(KFD_DRIVER_MAJOR) "." |
|---|
| 189 | | - __stringify(KFD_DRIVER_MINOR) "." |
|---|
| 190 | | - __stringify(KFD_DRIVER_PATCHLEVEL)); |
|---|
| 91 | +void kgd2kfd_exit(void) |
|---|
| 92 | +{ |
|---|
| 93 | + kfd_exit(); |
|---|
| 94 | +} |
|---|