1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
4  */
5 
6 #include "iris_hfi_gen2.h"
7 #include "iris_hfi_gen2_packet.h"
8 
9 #define NUM_SYS_INIT_PACKETS 8
10 
11 #define SYS_INIT_PKT_SIZE (sizeof(struct iris_hfi_header) + \
12 	NUM_SYS_INIT_PACKETS * (sizeof(struct iris_hfi_packet) + sizeof(u32)))
13 
14 #define SYS_IFPC_PKT_SIZE (sizeof(struct iris_hfi_header) + \
15 	sizeof(struct iris_hfi_packet) + sizeof(u32))
16 
17 #define SYS_NO_PAYLOAD_PKT_SIZE (sizeof(struct iris_hfi_header) + \
18 	sizeof(struct iris_hfi_packet))
19 
20 static int iris_hfi_gen2_sys_init(struct iris_core *core)
21 {
22 	struct iris_hfi_header *hdr;
23 	int ret;
24 
25 	hdr = kzalloc(SYS_INIT_PKT_SIZE, GFP_KERNEL);
26 	if (!hdr)
27 		return -ENOMEM;
28 
29 	iris_hfi_gen2_packet_sys_init(core, hdr);
30 	ret = iris_hfi_queue_cmd_write_locked(core, hdr, hdr->size);
31 
32 	kfree(hdr);
33 
34 	return ret;
35 }
36 
37 static int iris_hfi_gen2_sys_image_version(struct iris_core *core)
38 {
39 	struct iris_hfi_header *hdr;
40 	int ret;
41 
42 	hdr = kzalloc(SYS_NO_PAYLOAD_PKT_SIZE, GFP_KERNEL);
43 	if (!hdr)
44 		return -ENOMEM;
45 
46 	iris_hfi_gen2_packet_image_version(core, hdr);
47 	ret = iris_hfi_queue_cmd_write_locked(core, hdr, hdr->size);
48 
49 	kfree(hdr);
50 
51 	return ret;
52 }
53 
54 static int iris_hfi_gen2_sys_interframe_powercollapse(struct iris_core *core)
55 {
56 	struct iris_hfi_header *hdr;
57 	int ret;
58 
59 	hdr = kzalloc(SYS_IFPC_PKT_SIZE, GFP_KERNEL);
60 	if (!hdr)
61 		return -ENOMEM;
62 
63 	iris_hfi_gen2_packet_sys_interframe_powercollapse(core, hdr);
64 	ret = iris_hfi_queue_cmd_write_locked(core, hdr, hdr->size);
65 
66 	kfree(hdr);
67 
68 	return ret;
69 }
70 
71 static int iris_hfi_gen2_sys_pc_prep(struct iris_core *core)
72 {
73 	struct iris_hfi_header *hdr;
74 	int ret;
75 
76 	hdr = kzalloc(SYS_NO_PAYLOAD_PKT_SIZE, GFP_KERNEL);
77 	if (!hdr)
78 		return -ENOMEM;
79 
80 	iris_hfi_gen2_packet_sys_pc_prep(core, hdr);
81 	ret = iris_hfi_queue_cmd_write_locked(core, hdr, hdr->size);
82 
83 	kfree(hdr);
84 
85 	return ret;
86 }
87 
88 static const struct iris_hfi_command_ops iris_hfi_gen2_command_ops = {
89 	.sys_init = iris_hfi_gen2_sys_init,
90 	.sys_image_version = iris_hfi_gen2_sys_image_version,
91 	.sys_interframe_powercollapse = iris_hfi_gen2_sys_interframe_powercollapse,
92 	.sys_pc_prep = iris_hfi_gen2_sys_pc_prep,
93 };
94 
95 void iris_hfi_gen2_command_ops_init(struct iris_core *core)
96 {
97 	core->hfi_ops = &iris_hfi_gen2_command_ops;
98 }
99 
100 struct iris_inst *iris_hfi_gen2_get_instance(void)
101 {
102 	return kzalloc(sizeof(struct iris_inst_hfi_gen2), GFP_KERNEL);
103 }
104