blob: 3f34ae16f0750a04365c75cf448d66574e16e9b6 [file] [log] [blame]
Oded Gabbay4a488a72014-07-16 21:08:55 +03001/*
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>
Oded Gabbay4a488a72014-07-16 21:08:55 +030025#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"
Oded Gabbayf9dcced2015-01-22 14:57:52 +020032#define KFD_DRIVER_DATE "20150122"
Oded Gabbay4a488a72014-07-16 21:08:55 +030033#define KFD_DRIVER_MAJOR 0
34#define KFD_DRIVER_MINOR 7
Oded Gabbayf9dcced2015-01-22 14:57:52 +020035#define KFD_DRIVER_PATCHLEVEL 1
Oded Gabbay4a488a72014-07-16 21:08:55 +030036
37const struct kfd2kgd_calls *kfd2kgd;
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};
47
Ben Goz31c21fe2014-07-17 00:48:28 +030048int sched_policy = KFD_SCHED_POLICY_HWS;
49module_param(sched_policy, int, 0444);
50MODULE_PARM_DESC(sched_policy,
Ben Gozcb2ac442015-01-18 13:18:01 +020051 "Scheduling policy (0 = HWS (Default), 1 = HWS without over-subscription, 2 = Non-HWS (Used for debugging only)");
Ben Goz31c21fe2014-07-17 00:48:28 +030052
Oded Gabbayb8cbab02015-01-18 13:18:01 +020053int max_num_of_queues_per_device = KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT;
54module_param(max_num_of_queues_per_device, int, 0444);
55MODULE_PARM_DESC(max_num_of_queues_per_device,
56 "Maximum number of supported queues per device (1 = Minimum, 4096 = default)");
Oded Gabbay19f6d2a2014-07-16 23:25:31 +030057
Oded Gabbay4a488a72014-07-16 21:08:55 +030058bool kgd2kfd_init(unsigned interface_version,
59 const struct kfd2kgd_calls *f2g,
60 const struct kgd2kfd_calls **g2f)
61{
62 /*
63 * Only one interface version is supported,
64 * no kfd/kgd version skew allowed.
65 */
66 if (interface_version != KFD_INTERFACE_VERSION)
67 return false;
68
Oded Gabbay19f6d2a2014-07-16 23:25:31 +030069 /* Protection against multiple amd kgd loads */
70 if (kfd2kgd)
71 return true;
72
Oded Gabbay4a488a72014-07-16 21:08:55 +030073 kfd2kgd = f2g;
74 *g2f = &kgd2kfd;
75
76 return true;
77}
78EXPORT_SYMBOL(kgd2kfd_init);
79
80void kgd2kfd_exit(void)
81{
82}
83
84static int __init kfd_module_init(void)
85{
86 int err;
87
Oded Gabbay19f6d2a2014-07-16 23:25:31 +030088 kfd2kgd = NULL;
89
90 /* Verify module parameters */
Ben Goz31c21fe2014-07-17 00:48:28 +030091 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 */
Oded Gabbayca400b22015-01-29 10:33:34 +020098 if ((max_num_of_queues_per_device < 1) ||
Oded Gabbayb8cbab02015-01-18 13:18:01 +020099 (max_num_of_queues_per_device >
100 KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) {
Oded Gabbayca400b22015-01-29 10:33:34 +0200101 pr_err("kfd: max_num_of_queues_per_device must be between 1 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n");
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300102 return -1;
103 }
104
105 err = kfd_pasid_init();
106 if (err < 0)
107 goto err_pasid;
108
Oded Gabbay4a488a72014-07-16 21:08:55 +0300109 err = kfd_chardev_init();
110 if (err < 0)
111 goto err_ioctl;
112
Evgeny Pinchuk5b5c4e42014-07-16 21:22:32 +0300113 err = kfd_topology_init();
114 if (err < 0)
115 goto err_topology;
116
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300117 kfd_process_create_wq();
118
Oded Gabbay4a488a72014-07-16 21:08:55 +0300119 dev_info(kfd_device, "Initialized module\n");
120
121 return 0;
122
Evgeny Pinchuk5b5c4e42014-07-16 21:22:32 +0300123err_topology:
124 kfd_chardev_exit();
Oded Gabbay4a488a72014-07-16 21:08:55 +0300125err_ioctl:
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300126 kfd_pasid_exit();
127err_pasid:
Oded Gabbay4a488a72014-07-16 21:08:55 +0300128 return err;
129}
130
131static void __exit kfd_module_exit(void)
132{
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300133 kfd_process_destroy_wq();
Evgeny Pinchuk5b5c4e42014-07-16 21:22:32 +0300134 kfd_topology_shutdown();
Oded Gabbay4a488a72014-07-16 21:08:55 +0300135 kfd_chardev_exit();
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300136 kfd_pasid_exit();
Oded Gabbay4a488a72014-07-16 21:08:55 +0300137 dev_info(kfd_device, "Removed module\n");
138}
139
140module_init(kfd_module_init);
141module_exit(kfd_module_exit);
142
143MODULE_AUTHOR(KFD_DRIVER_AUTHOR);
144MODULE_DESCRIPTION(KFD_DRIVER_DESC);
145MODULE_LICENSE("GPL and additional rights");
146MODULE_VERSION(__stringify(KFD_DRIVER_MAJOR) "."
147 __stringify(KFD_DRIVER_MINOR) "."
148 __stringify(KFD_DRIVER_PATCHLEVEL));