kfd_module.c 5.0 KB
Newer Older
O
Oded Gabbay 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * 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>
27
#include <linux/printk.h>
O
Oded Gabbay 已提交
28 29 30 31 32
#include "kfd_priv.h"

#define KFD_DRIVER_AUTHOR	"AMD Inc. and others"

#define KFD_DRIVER_DESC		"Standalone HSA driver for AMD's GPUs"
33
#define KFD_DRIVER_DATE		"20150421"
O
Oded Gabbay 已提交
34 35
#define KFD_DRIVER_MAJOR	0
#define KFD_DRIVER_MINOR	7
36
#define KFD_DRIVER_PATCHLEVEL	2
O
Oded Gabbay 已提交
37 38 39 40 41 42 43 44 45

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,
46 47
	.schedule_evict_and_restore_process =
			  kgd2kfd_schedule_evict_and_restore_process,
O
Oded Gabbay 已提交
48 49
};

50 51 52
int sched_policy = KFD_SCHED_POLICY_HWS;
module_param(sched_policy, int, 0444);
MODULE_PARM_DESC(sched_policy,
53
	"Scheduling policy (0 = HWS (Default), 1 = HWS without over-subscription, 2 = Non-HWS (Used for debugging only)");
54

55 56 57 58 59
int hws_max_conc_proc = 8;
module_param(hws_max_conc_proc, int, 0444);
MODULE_PARM_DESC(hws_max_conc_proc,
	"Max # processes HWS can execute concurrently when sched_policy=0 (0 = no concurrency, #VMIDs for KFD = Maximum(default))");

F
Felix Kuehling 已提交
60 61 62 63
int cwsr_enable = 1;
module_param(cwsr_enable, int, 0444);
MODULE_PARM_DESC(cwsr_enable, "CWSR enable (0 = Off, 1 = On (Default))");

64 65 66 67
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)");
68

69 70 71 72 73
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)");

74 75 76 77 78
int debug_largebar;
module_param(debug_largebar, int, 0444);
MODULE_PARM_DESC(debug_largebar,
	"Debug large-bar flag used to simulate large-bar capability on non-large bar machine (0 = disable, 1 = enable)");

79 80 81 82 83
int ignore_crat;
module_param(ignore_crat, int, 0444);
MODULE_PARM_DESC(ignore_crat,
	"Ignore CRAT table during KFD initialization (0 = use CRAT (default), 1 = ignore CRAT)");

84 85
static int amdkfd_init_completed;

86 87
int kgd2kfd_init(unsigned int interface_version,
		const struct kgd2kfd_calls **g2f)
O
Oded Gabbay 已提交
88
{
89 90 91
	if (!amdkfd_init_completed)
		return -EPROBE_DEFER;

O
Oded Gabbay 已提交
92 93 94 95 96
	/*
	 * Only one interface version is supported,
	 * no kfd/kgd version skew allowed.
	 */
	if (interface_version != KFD_INTERFACE_VERSION)
97
		return -EINVAL;
O
Oded Gabbay 已提交
98 99 100

	*g2f = &kgd2kfd;

101
	return 0;
O
Oded Gabbay 已提交
102 103 104 105 106 107 108 109 110 111 112
}
EXPORT_SYMBOL(kgd2kfd_init);

void kgd2kfd_exit(void)
{
}

static int __init kfd_module_init(void)
{
	int err;

113 114 115
	/* Verify module parameters */
	if ((sched_policy < KFD_SCHED_POLICY_HWS) ||
		(sched_policy > KFD_SCHED_POLICY_NO_HWS)) {
116
		pr_err("sched_policy has invalid value\n");
117 118 119
		return -1;
	}

120
	/* Verify module parameters */
121
	if ((max_num_of_queues_per_device < 1) ||
122 123
		(max_num_of_queues_per_device >
			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 126 127
		return -1;
	}

O
Oded Gabbay 已提交
128 129 130 131
	err = kfd_chardev_init();
	if (err < 0)
		goto err_ioctl;

132 133 134 135
	err = kfd_topology_init();
	if (err < 0)
		goto err_topology;

136 137 138
	err = kfd_process_create_wq();
	if (err < 0)
		goto err_create_wq;
139

140 141
	kfd_debugfs_init();

142 143
	amdkfd_init_completed = 1;

O
Oded Gabbay 已提交
144 145 146 147
	dev_info(kfd_device, "Initialized module\n");

	return 0;

148 149
err_create_wq:
	kfd_topology_shutdown();
150 151
err_topology:
	kfd_chardev_exit();
O
Oded Gabbay 已提交
152 153 154 155 156 157
err_ioctl:
	return err;
}

static void __exit kfd_module_exit(void)
{
158 159
	amdkfd_init_completed = 0;

160
	kfd_debugfs_fini();
161
	kfd_process_destroy_wq();
162
	kfd_topology_shutdown();
O
Oded Gabbay 已提交
163
	kfd_chardev_exit();
164
	pr_info("amdkfd: Removed module\n");
O
Oded Gabbay 已提交
165 166 167 168 169 170 171 172 173 174 175
}

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));