Loading...
1/* SPDX-License-Identifier: GPL-2.0 OR MIT */
2/*
3 * Copyright 2014-2022 Advanced Micro Devices, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25#ifndef KFD_KERNEL_QUEUE_H_
26#define KFD_KERNEL_QUEUE_H_
27
28#include <linux/list.h>
29#include <linux/types.h>
30#include "kfd_priv.h"
31
32/**
33 * kq_acquire_packet_buffer: Returns a pointer to the location in the kernel
34 * queue ring buffer where the calling function can write its packet. It is
35 * Guaranteed that there is enough space for that packet. It also updates the
36 * pending write pointer to that location so subsequent calls to
37 * acquire_packet_buffer will get a correct write pointer
38 *
39 * kq_submit_packet: Update the write pointer and doorbell of a kernel queue.
40 *
41 * kq_rollback_packet: This routine is called if we failed to build an acquired
42 * packet for some reason. It just overwrites the pending wptr with the current
43 * one
44 *
45 */
46
47int kq_acquire_packet_buffer(struct kernel_queue *kq,
48 size_t packet_size_in_dwords,
49 unsigned int **buffer_ptr);
50int kq_submit_packet(struct kernel_queue *kq);
51void kq_rollback_packet(struct kernel_queue *kq);
52
53
54struct kernel_queue {
55 /* data */
56 struct kfd_node *dev;
57 struct mqd_manager *mqd_mgr;
58 struct queue *queue;
59 uint64_t pending_wptr64;
60 uint32_t pending_wptr;
61 unsigned int nop_packet;
62
63 struct kfd_mem_obj *rptr_mem;
64 uint32_t *rptr_kernel;
65 uint64_t rptr_gpu_addr;
66 struct kfd_mem_obj *wptr_mem;
67 union {
68 uint64_t *wptr64_kernel;
69 uint32_t *wptr_kernel;
70 };
71 uint64_t wptr_gpu_addr;
72 struct kfd_mem_obj *pq;
73 uint64_t pq_gpu_addr;
74 uint32_t *pq_kernel_addr;
75 struct kfd_mem_obj *eop_mem;
76 uint64_t eop_gpu_addr;
77 uint32_t *eop_kernel_addr;
78
79 struct kfd_mem_obj *fence_mem_obj;
80 uint64_t fence_gpu_addr;
81 void *fence_kernel_address;
82
83 struct list_head list;
84};
85
86#endif /* KFD_KERNEL_QUEUE_H_ */
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
24#ifndef KFD_KERNEL_QUEUE_H_
25#define KFD_KERNEL_QUEUE_H_
26
27#include <linux/list.h>
28#include <linux/types.h>
29#include "kfd_priv.h"
30
31/**
32 * struct kernel_queue_ops
33 *
34 * @initialize: Initialize a kernel queue, including allocations of GART memory
35 * needed for the queue.
36 *
37 * @uninitialize: Uninitialize a kernel queue and free all its memory usages.
38 *
39 * @acquire_packet_buffer: Returns a pointer to the location in the kernel
40 * queue ring buffer where the calling function can write its packet. It is
41 * Guaranteed that there is enough space for that packet. It also updates the
42 * pending write pointer to that location so subsequent calls to
43 * acquire_packet_buffer will get a correct write pointer
44 *
45 * @submit_packet: Update the write pointer and doorbell of a kernel queue.
46 *
47 * @sync_with_hw: Wait until the write pointer and the read pointer of a kernel
48 * queue are equal, which means the CP has read all the submitted packets.
49 *
50 * @rollback_packet: This routine is called if we failed to build an acquired
51 * packet for some reason. It just overwrites the pending wptr with the current
52 * one
53 *
54 */
55struct kernel_queue_ops {
56 bool (*initialize)(struct kernel_queue *kq, struct kfd_dev *dev,
57 enum kfd_queue_type type, unsigned int queue_size);
58 void (*uninitialize)(struct kernel_queue *kq);
59 int (*acquire_packet_buffer)(struct kernel_queue *kq,
60 size_t packet_size_in_dwords,
61 unsigned int **buffer_ptr);
62
63 void (*submit_packet)(struct kernel_queue *kq);
64 void (*rollback_packet)(struct kernel_queue *kq);
65};
66
67struct kernel_queue {
68 struct kernel_queue_ops ops;
69 struct kernel_queue_ops ops_asic_specific;
70
71 /* data */
72 struct kfd_dev *dev;
73 struct mqd_manager *mqd_mgr;
74 struct queue *queue;
75 uint64_t pending_wptr64;
76 uint32_t pending_wptr;
77 unsigned int nop_packet;
78
79 struct kfd_mem_obj *rptr_mem;
80 uint32_t *rptr_kernel;
81 uint64_t rptr_gpu_addr;
82 struct kfd_mem_obj *wptr_mem;
83 union {
84 uint64_t *wptr64_kernel;
85 uint32_t *wptr_kernel;
86 };
87 uint64_t wptr_gpu_addr;
88 struct kfd_mem_obj *pq;
89 uint64_t pq_gpu_addr;
90 uint32_t *pq_kernel_addr;
91 struct kfd_mem_obj *eop_mem;
92 uint64_t eop_gpu_addr;
93 uint32_t *eop_kernel_addr;
94
95 struct kfd_mem_obj *fence_mem_obj;
96 uint64_t fence_gpu_addr;
97 void *fence_kernel_address;
98
99 struct list_head list;
100};
101
102void kernel_queue_init_cik(struct kernel_queue_ops *ops);
103void kernel_queue_init_vi(struct kernel_queue_ops *ops);
104void kernel_queue_init_v9(struct kernel_queue_ops *ops);
105void kernel_queue_init_v10(struct kernel_queue_ops *ops);
106
107#endif /* KFD_KERNEL_QUEUE_H_ */