Linux Audio

Check our new training course

Linux kernel drivers training

May 6-19, 2025
Register
Loading...
v4.6
  1/*
  2 * Copyright 2014 Advanced Micro Devices, Inc.
  3 *
  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:
 10 *
 11 * The above copyright notice and this permission notice shall be included in
 12 * all copies or substantial portions of the Software.
 13 *
 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.
 21 */
 22
 23#include <linux/module.h>
 24#include <linux/sched.h>
 25#include <linux/moduleparam.h>
 26#include <linux/device.h>
 
 27#include "kfd_priv.h"
 28
 29#define KFD_DRIVER_AUTHOR	"AMD Inc. and others"
 30
 31#define KFD_DRIVER_DESC		"Standalone HSA driver for AMD's GPUs"
 32#define KFD_DRIVER_DATE		"20150421"
 33#define KFD_DRIVER_MAJOR	0
 34#define KFD_DRIVER_MINOR	7
 35#define KFD_DRIVER_PATCHLEVEL	2
 36
 37static const struct kgd2kfd_calls kgd2kfd = {
 38	.exit		= kgd2kfd_exit,
 39	.probe		= kgd2kfd_probe,
 40	.device_init	= kgd2kfd_device_init,
 41	.device_exit	= kgd2kfd_device_exit,
 42	.interrupt	= kgd2kfd_interrupt,
 43	.suspend	= kgd2kfd_suspend,
 44	.resume		= kgd2kfd_resume,
 
 
 45};
 46
 47int sched_policy = KFD_SCHED_POLICY_HWS;
 48module_param(sched_policy, int, 0444);
 49MODULE_PARM_DESC(sched_policy,
 50	"Scheduling policy (0 = HWS (Default), 1 = HWS without over-subscription, 2 = Non-HWS (Used for debugging only)");
 51
 
 
 
 
 
 
 
 
 
 52int max_num_of_queues_per_device = KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT;
 53module_param(max_num_of_queues_per_device, int, 0444);
 54MODULE_PARM_DESC(max_num_of_queues_per_device,
 55	"Maximum number of supported queues per device (1 = Minimum, 4096 = default)");
 56
 57int send_sigterm;
 58module_param(send_sigterm, int, 0444);
 59MODULE_PARM_DESC(send_sigterm,
 60	"Send sigterm to HSA process on unhandled exception (0 = disable, 1 = enable)");
 61
 
 
 
 
 
 
 
 
 
 
 62static int amdkfd_init_completed;
 63
 64int kgd2kfd_init(unsigned interface_version, const struct kgd2kfd_calls **g2f)
 
 65{
 66	if (!amdkfd_init_completed)
 67		return -EPROBE_DEFER;
 68
 69	/*
 70	 * Only one interface version is supported,
 71	 * no kfd/kgd version skew allowed.
 72	 */
 73	if (interface_version != KFD_INTERFACE_VERSION)
 74		return -EINVAL;
 75
 76	*g2f = &kgd2kfd;
 77
 78	return 0;
 79}
 80EXPORT_SYMBOL(kgd2kfd_init);
 81
 82void kgd2kfd_exit(void)
 83{
 84}
 85
 86static int __init kfd_module_init(void)
 87{
 88	int err;
 89
 90	/* Verify module parameters */
 91	if ((sched_policy < KFD_SCHED_POLICY_HWS) ||
 92		(sched_policy > KFD_SCHED_POLICY_NO_HWS)) {
 93		pr_err("kfd: sched_policy has invalid value\n");
 94		return -1;
 95	}
 96
 97	/* Verify module parameters */
 98	if ((max_num_of_queues_per_device < 1) ||
 99		(max_num_of_queues_per_device >
100			KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) {
101		pr_err("kfd: max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n");
102		return -1;
103	}
104
105	err = kfd_pasid_init();
106	if (err < 0)
107		goto err_pasid;
108
109	err = kfd_chardev_init();
110	if (err < 0)
111		goto err_ioctl;
112
113	err = kfd_topology_init();
114	if (err < 0)
115		goto err_topology;
116
117	kfd_process_create_wq();
 
 
 
 
118
119	amdkfd_init_completed = 1;
120
121	dev_info(kfd_device, "Initialized module\n");
122
123	return 0;
124
 
 
125err_topology:
126	kfd_chardev_exit();
127err_ioctl:
128	kfd_pasid_exit();
129err_pasid:
130	return err;
131}
132
133static void __exit kfd_module_exit(void)
134{
135	amdkfd_init_completed = 0;
136
 
137	kfd_process_destroy_wq();
138	kfd_topology_shutdown();
139	kfd_chardev_exit();
140	kfd_pasid_exit();
141	dev_info(kfd_device, "Removed module\n");
142}
143
144module_init(kfd_module_init);
145module_exit(kfd_module_exit);
146
147MODULE_AUTHOR(KFD_DRIVER_AUTHOR);
148MODULE_DESCRIPTION(KFD_DRIVER_DESC);
149MODULE_LICENSE("GPL and additional rights");
150MODULE_VERSION(__stringify(KFD_DRIVER_MAJOR) "."
151	       __stringify(KFD_DRIVER_MINOR) "."
152	       __stringify(KFD_DRIVER_PATCHLEVEL));
v4.17
  1/*
  2 * Copyright 2014 Advanced Micro Devices, Inc.
  3 *
  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:
 10 *
 11 * The above copyright notice and this permission notice shall be included in
 12 * all copies or substantial portions of the Software.
 13 *
 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.
 21 */
 22
 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>
 28#include "kfd_priv.h"
 29
 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
 38static 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	.schedule_evict_and_restore_process =
 47			  kgd2kfd_schedule_evict_and_restore_process,
 48};
 49
 50int sched_policy = KFD_SCHED_POLICY_HWS;
 51module_param(sched_policy, int, 0444);
 52MODULE_PARM_DESC(sched_policy,
 53	"Scheduling policy (0 = HWS (Default), 1 = HWS without over-subscription, 2 = Non-HWS (Used for debugging only)");
 54
 55int hws_max_conc_proc = 8;
 56module_param(hws_max_conc_proc, int, 0444);
 57MODULE_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))");
 59
 60int cwsr_enable = 1;
 61module_param(cwsr_enable, int, 0444);
 62MODULE_PARM_DESC(cwsr_enable, "CWSR enable (0 = Off, 1 = On (Default))");
 63
 64int max_num_of_queues_per_device = KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT;
 65module_param(max_num_of_queues_per_device, int, 0444);
 66MODULE_PARM_DESC(max_num_of_queues_per_device,
 67	"Maximum number of supported queues per device (1 = Minimum, 4096 = default)");
 68
 69int send_sigterm;
 70module_param(send_sigterm, int, 0444);
 71MODULE_PARM_DESC(send_sigterm,
 72	"Send sigterm to HSA process on unhandled exception (0 = disable, 1 = enable)");
 73
 74int debug_largebar;
 75module_param(debug_largebar, int, 0444);
 76MODULE_PARM_DESC(debug_largebar,
 77	"Debug large-bar flag used to simulate large-bar capability on non-large bar machine (0 = disable, 1 = enable)");
 78
 79int ignore_crat;
 80module_param(ignore_crat, int, 0444);
 81MODULE_PARM_DESC(ignore_crat,
 82	"Ignore CRAT table during KFD initialization (0 = use CRAT (default), 1 = ignore CRAT)");
 83
 84static int amdkfd_init_completed;
 85
 86int kgd2kfd_init(unsigned int interface_version,
 87		const struct kgd2kfd_calls **g2f)
 88{
 89	if (!amdkfd_init_completed)
 90		return -EPROBE_DEFER;
 91
 92	/*
 93	 * Only one interface version is supported,
 94	 * no kfd/kgd version skew allowed.
 95	 */
 96	if (interface_version != KFD_INTERFACE_VERSION)
 97		return -EINVAL;
 98
 99	*g2f = &kgd2kfd;
100
101	return 0;
102}
103EXPORT_SYMBOL(kgd2kfd_init);
104
105void kgd2kfd_exit(void)
106{
107}
108
109static int __init kfd_module_init(void)
110{
111	int err;
112
113	/* Verify module parameters */
114	if ((sched_policy < KFD_SCHED_POLICY_HWS) ||
115		(sched_policy > KFD_SCHED_POLICY_NO_HWS)) {
116		pr_err("sched_policy has invalid value\n");
117		return -1;
118	}
119
120	/* Verify module parameters */
121	if ((max_num_of_queues_per_device < 1) ||
122		(max_num_of_queues_per_device >
123			KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) {
124		pr_err("max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n");
125		return -1;
126	}
127
 
 
 
 
128	err = kfd_chardev_init();
129	if (err < 0)
130		goto err_ioctl;
131
132	err = kfd_topology_init();
133	if (err < 0)
134		goto err_topology;
135
136	err = kfd_process_create_wq();
137	if (err < 0)
138		goto err_create_wq;
139
140	kfd_debugfs_init();
141
142	amdkfd_init_completed = 1;
143
144	dev_info(kfd_device, "Initialized module\n");
145
146	return 0;
147
148err_create_wq:
149	kfd_topology_shutdown();
150err_topology:
151	kfd_chardev_exit();
152err_ioctl:
 
 
153	return err;
154}
155
156static void __exit kfd_module_exit(void)
157{
158	amdkfd_init_completed = 0;
159
160	kfd_debugfs_fini();
161	kfd_process_destroy_wq();
162	kfd_topology_shutdown();
163	kfd_chardev_exit();
164	pr_info("amdkfd: Removed module\n");
 
165}
166
167module_init(kfd_module_init);
168module_exit(kfd_module_exit);
169
170MODULE_AUTHOR(KFD_DRIVER_AUTHOR);
171MODULE_DESCRIPTION(KFD_DRIVER_DESC);
172MODULE_LICENSE("GPL and additional rights");
173MODULE_VERSION(__stringify(KFD_DRIVER_MAJOR) "."
174	       __stringify(KFD_DRIVER_MINOR) "."
175	       __stringify(KFD_DRIVER_PATCHLEVEL));