forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/gpu/drm/tegra/falcon.c
....@@ -1,9 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2015, NVIDIA Corporation.
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 as
6
- * published by the Free Software Foundation.
74 */
85
96 #include <linux/platform_device.h>
....@@ -61,32 +58,17 @@
6158 static void falcon_copy_firmware_image(struct falcon *falcon,
6259 const struct firmware *firmware)
6360 {
64
- u32 *firmware_vaddr = falcon->firmware.vaddr;
65
- dma_addr_t daddr;
61
+ u32 *virt = falcon->firmware.virt;
6662 size_t i;
67
- int err;
6863
6964 /* copy the whole thing taking into account endianness */
7065 for (i = 0; i < firmware->size / sizeof(u32); i++)
71
- firmware_vaddr[i] = le32_to_cpu(((u32 *)firmware->data)[i]);
72
-
73
- /* ensure that caches are flushed and falcon can see the firmware */
74
- daddr = dma_map_single(falcon->dev, firmware_vaddr,
75
- falcon->firmware.size, DMA_TO_DEVICE);
76
- err = dma_mapping_error(falcon->dev, daddr);
77
- if (err) {
78
- dev_err(falcon->dev, "failed to map firmware: %d\n", err);
79
- return;
80
- }
81
- dma_sync_single_for_device(falcon->dev, daddr,
82
- falcon->firmware.size, DMA_TO_DEVICE);
83
- dma_unmap_single(falcon->dev, daddr, falcon->firmware.size,
84
- DMA_TO_DEVICE);
66
+ virt[i] = le32_to_cpu(((u32 *)firmware->data)[i]);
8567 }
8668
8769 static int falcon_parse_firmware_image(struct falcon *falcon)
8870 {
89
- struct falcon_fw_bin_header_v1 *bin = (void *)falcon->firmware.vaddr;
71
+ struct falcon_fw_bin_header_v1 *bin = (void *)falcon->firmware.virt;
9072 struct falcon_fw_os_header_v1 *os;
9173
9274 /* endian problems would show up right here */
....@@ -107,7 +89,7 @@
10789 return -EINVAL;
10890 }
10991
110
- os = falcon->firmware.vaddr + bin->os_header_offset;
92
+ os = falcon->firmware.virt + bin->os_header_offset;
11193
11294 falcon->firmware.bin_data.size = bin->os_size;
11395 falcon->firmware.bin_data.offset = bin->os_data_offset;
....@@ -128,6 +110,8 @@
128110 if (err < 0)
129111 return err;
130112
113
+ falcon->firmware.size = falcon->firmware.firmware->size;
114
+
131115 return 0;
132116 }
133117
....@@ -136,16 +120,6 @@
136120 const struct firmware *firmware = falcon->firmware.firmware;
137121 int err;
138122
139
- falcon->firmware.size = firmware->size;
140
-
141
- /* allocate iova space for the firmware */
142
- falcon->firmware.vaddr = falcon->ops->alloc(falcon, firmware->size,
143
- &falcon->firmware.paddr);
144
- if (!falcon->firmware.vaddr) {
145
- dev_err(falcon->dev, "dma memory mapping failed\n");
146
- return -ENOMEM;
147
- }
148
-
149123 /* copy firmware image into local area. this also ensures endianness */
150124 falcon_copy_firmware_image(falcon, firmware);
151125
....@@ -153,59 +127,48 @@
153127 err = falcon_parse_firmware_image(falcon);
154128 if (err < 0) {
155129 dev_err(falcon->dev, "failed to parse firmware image\n");
156
- goto err_setup_firmware_image;
130
+ return err;
157131 }
158132
159133 release_firmware(firmware);
160134 falcon->firmware.firmware = NULL;
161135
162136 return 0;
163
-
164
-err_setup_firmware_image:
165
- falcon->ops->free(falcon, falcon->firmware.size,
166
- falcon->firmware.paddr, falcon->firmware.vaddr);
167
-
168
- return err;
169137 }
170138
171139 int falcon_init(struct falcon *falcon)
172140 {
173
- /* check mandatory ops */
174
- if (!falcon->ops || !falcon->ops->alloc || !falcon->ops->free)
175
- return -EINVAL;
176
-
177
- falcon->firmware.vaddr = NULL;
141
+ falcon->firmware.virt = NULL;
178142
179143 return 0;
180144 }
181145
182146 void falcon_exit(struct falcon *falcon)
183147 {
184
- if (falcon->firmware.firmware) {
148
+ if (falcon->firmware.firmware)
185149 release_firmware(falcon->firmware.firmware);
186
- falcon->firmware.firmware = NULL;
187
- }
188
-
189
- if (falcon->firmware.vaddr) {
190
- falcon->ops->free(falcon, falcon->firmware.size,
191
- falcon->firmware.paddr,
192
- falcon->firmware.vaddr);
193
- falcon->firmware.vaddr = NULL;
194
- }
195150 }
196151
197152 int falcon_boot(struct falcon *falcon)
198153 {
199154 unsigned long offset;
155
+ u32 value;
200156 int err;
201157
202
- if (!falcon->firmware.vaddr)
158
+ if (!falcon->firmware.virt)
203159 return -EINVAL;
160
+
161
+ err = readl_poll_timeout(falcon->regs + FALCON_DMACTL, value,
162
+ (value & (FALCON_DMACTL_IMEM_SCRUBBING |
163
+ FALCON_DMACTL_DMEM_SCRUBBING)) == 0,
164
+ 10, 10000);
165
+ if (err < 0)
166
+ return err;
204167
205168 falcon_writel(falcon, 0, FALCON_DMACTL);
206169
207170 /* setup the address of the binary data so Falcon can access it later */
208
- falcon_writel(falcon, (falcon->firmware.paddr +
171
+ falcon_writel(falcon, (falcon->firmware.iova +
209172 falcon->firmware.bin_data.offset) >> 8,
210173 FALCON_DMATRFBASE);
211174