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.
24 #include <linux/types.h>
25 #include <linux/kernel.h>
26 #include <linux/log2.h>
27 #include <linux/sched.h>
28 #include <linux/slab.h>
29 #include <linux/mutex.h>
30 #include <linux/device.h>
32 #include "kfd_pm4_headers.h"
33 #include "kfd_pm4_headers_diq.h"
34 #include "kfd_kernel_queue.h"
36 #include "kfd_pm4_opcodes.h"
38 #include "kfd_dbgmgr.h"
39 #include "kfd_dbgdev.h"
40 #include "kfd_device_queue_manager.h"
41 #include "../../radeon/cik_reg.h"
43 static void dbgdev_address_watch_disable_nodiq(struct kfd_dev
*dev
)
45 BUG_ON(!dev
|| !dev
->kfd2kgd
);
47 dev
->kfd2kgd
->address_watch_disable(dev
->kgd
);
50 static int dbgdev_register_nodiq(struct kfd_dbgdev
*dbgdev
)
55 * no action is needed in this case,
56 * just make sure diq will not be used
64 static int dbgdev_register_diq(struct kfd_dbgdev
*dbgdev
)
66 struct queue_properties properties
;
68 struct kernel_queue
*kq
= NULL
;
71 BUG_ON(!dbgdev
|| !dbgdev
->pqm
|| !dbgdev
->dev
);
73 status
= pqm_create_queue(dbgdev
->pqm
, dbgdev
->dev
, NULL
,
74 &properties
, 0, KFD_QUEUE_TYPE_DIQ
,
78 pr_err("amdkfd: Failed to create DIQ\n");
82 pr_debug("DIQ Created with queue id: %d\n", qid
);
84 kq
= pqm_get_kernel_queue(dbgdev
->pqm
, qid
);
87 pr_err("amdkfd: Error getting DIQ\n");
88 pqm_destroy_queue(dbgdev
->pqm
, qid
);
97 static int dbgdev_unregister_nodiq(struct kfd_dbgdev
*dbgdev
)
99 BUG_ON(!dbgdev
|| !dbgdev
->dev
);
101 /* disable watch address */
102 dbgdev_address_watch_disable_nodiq(dbgdev
->dev
);
106 static int dbgdev_unregister_diq(struct kfd_dbgdev
*dbgdev
)
108 /* todo - disable address watch */
111 BUG_ON(!dbgdev
|| !dbgdev
->pqm
|| !dbgdev
->kq
);
113 status
= pqm_destroy_queue(dbgdev
->pqm
,
114 dbgdev
->kq
->queue
->properties
.queue_id
);
120 void kfd_dbgdev_init(struct kfd_dbgdev
*pdbgdev
, struct kfd_dev
*pdev
,
121 enum DBGDEV_TYPE type
)
123 BUG_ON(!pdbgdev
|| !pdev
);
127 pdbgdev
->type
= type
;
131 case DBGDEV_TYPE_NODIQ
:
132 pdbgdev
->dbgdev_register
= dbgdev_register_nodiq
;
133 pdbgdev
->dbgdev_unregister
= dbgdev_unregister_nodiq
;
135 case DBGDEV_TYPE_DIQ
:
137 pdbgdev
->dbgdev_register
= dbgdev_register_diq
;
138 pdbgdev
->dbgdev_unregister
= dbgdev_unregister_diq
;