Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 1 | /* |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 2 | * Copyright 2021-2023 Arm Limited and/or its affiliates |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 3 | * |
| 4 | * This program is free software and is provided to you under the terms of the |
| 5 | * GNU General Public License version 2 as published by the Free Software |
| 6 | * Foundation, and any use by you of this program is subject to the terms |
| 7 | * of such GNU licence. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, you can access it online at |
| 16 | * http://www.gnu.org/licenses/gpl-2.0.html. |
| 17 | * |
| 18 | * SPDX-License-Identifier: GPL-2.0-only |
| 19 | */ |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 20 | #include <linux/dma-mapping.h> |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 21 | #include <linux/firmware.h> |
| 22 | #include <linux/io.h> |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 23 | #include <linux/irqreturn.h> |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 24 | #include <linux/kernel.h> |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 25 | #include <linux/mailbox_client.h> |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 26 | #include <linux/module.h> |
| 27 | #include <linux/of.h> |
| 28 | #include <linux/of_address.h> |
| 29 | #include <linux/of_device.h> |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 30 | #include <linux/of_reserved_mem.h> |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 31 | #include <linux/platform_device.h> |
| 32 | #include <linux/remoteproc.h> |
| 33 | #include <linux/reset.h> |
Nir Ekhauz | 4823921 | 2021-11-23 10:28:34 +0200 | [diff] [blame] | 34 | #include <linux/version.h> |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 35 | #include <linux/workqueue.h> |
| 36 | |
| 37 | /**************************************************************************** |
| 38 | * Defines |
| 39 | ****************************************************************************/ |
| 40 | |
| 41 | #define DMA_ADDR_BITS 32 /* Number of address bits */ |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 42 | |
| 43 | #define ETHOSU_RPROC_DRIVER_VERSION "0.0.1" |
| 44 | |
| 45 | #define DEFAULT_FW_FILE "arm-ethos-u65.fw" |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 46 | #define DEFAULT_AUTO_BOOT false |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 47 | |
| 48 | /* firmware naming module parameter */ |
| 49 | static char fw_filename_param[256] = DEFAULT_FW_FILE; |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 50 | |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 51 | /* As the remoteproc is setup at probe, just allow the filename readonly */ |
| 52 | module_param_string(filename, fw_filename_param, sizeof(fw_filename_param), |
| 53 | 0444); |
| 54 | MODULE_PARM_DESC(filename, |
| 55 | "Filename for firmware image for Ethos-U remoteproc"); |
| 56 | |
| 57 | static bool auto_boot = DEFAULT_AUTO_BOOT; |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 58 | module_param(auto_boot, bool, 0); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 59 | MODULE_PARM_DESC(auto_boot, "Set to one to auto boot at load."); |
| 60 | |
| 61 | struct ethosu_rproc { |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 62 | struct device *dev; |
| 63 | struct reset_control *rstc; |
| 64 | struct mbox_client mbox_client; |
| 65 | struct mbox_chan *ch_rx; |
| 66 | struct mbox_chan *ch_tx; |
| 67 | struct workqueue_struct *wq; |
| 68 | struct work_struct work; |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 71 | /* declaration is in remoteproc_internal.h */ |
| 72 | extern irqreturn_t rproc_vq_interrupt(struct rproc *rproc, |
| 73 | int vq_id); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 74 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 75 | static void ethosu_mbox_bottom(struct work_struct *work) |
| 76 | { |
| 77 | struct ethosu_rproc *erproc = container_of( |
| 78 | work, struct ethosu_rproc, work); |
| 79 | struct rproc *rproc = dev_get_drvdata(erproc->dev); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 80 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 81 | dev_dbg(&rproc->dev, "Handle interrupt"); |
| 82 | |
| 83 | rproc_vq_interrupt(rproc, 0); |
| 84 | } |
| 85 | |
| 86 | static void ethosu_mbox_top(struct mbox_client *client, |
| 87 | void *message) |
| 88 | { |
| 89 | struct ethosu_rproc *erproc = container_of( |
| 90 | client, struct ethosu_rproc, mbox_client); |
| 91 | |
| 92 | queue_work(erproc->wq, &erproc->work); |
| 93 | } |
| 94 | |
| 95 | static dma_addr_t ethosu_of_pa_to_da(struct rproc *rproc, |
| 96 | const phys_addr_t pa, |
| 97 | const size_t size) |
| 98 | { |
| 99 | static const char of_rproc_ranges[] = "ethosu,dma-ranges"; |
| 100 | |
| 101 | struct device *dev = rproc->dev.parent; |
| 102 | struct device_node *np = dev->of_node; |
| 103 | const __be32 *rproc_ranges = of_get_property(np, of_rproc_ranges, NULL); |
| 104 | const int addr_cells = of_n_addr_cells(np); |
| 105 | const int size_cells = of_n_size_cells(np); |
| 106 | const int ranges_cells = addr_cells + addr_cells + size_cells; |
| 107 | int ranges_cnt; |
| 108 | int i; |
| 109 | |
| 110 | ranges_cnt = of_property_count_elems_of_size( |
| 111 | np, of_rproc_ranges, ranges_cells * sizeof(u32)); |
| 112 | |
| 113 | for (i = 0; i < ranges_cnt; i++) { |
| 114 | const int offset = i * ranges_cells; |
| 115 | |
| 116 | const uint64_t of_da = of_read_number( |
| 117 | &rproc_ranges[offset], addr_cells); |
| 118 | const uint64_t of_pa = of_read_number( |
| 119 | &rproc_ranges[offset + addr_cells], addr_cells); |
| 120 | const uint64_t of_size = of_read_number( |
| 121 | &rproc_ranges[offset + addr_cells + addr_cells], |
| 122 | size_cells); |
| 123 | |
| 124 | if (pa >= of_pa && (pa + size) <= (of_pa + of_size)) { |
| 125 | const dma_addr_t da = of_da + pa - of_pa; |
| 126 | |
| 127 | dev_dbg(dev, "PA to DA. pa=0x%llx, da=0x%llx", pa, da); |
| 128 | |
| 129 | return da; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | return (dma_addr_t)(-1); |
| 134 | } |
| 135 | |
| 136 | static int ethosu_add_carveout(struct rproc *rproc, |
| 137 | const phys_addr_t pa, |
| 138 | const size_t size, |
| 139 | const char *name) |
| 140 | { |
| 141 | struct device *dev = rproc->dev.parent; |
| 142 | dma_addr_t da; |
| 143 | void __iomem *va; |
| 144 | struct rproc_mem_entry *mem; |
| 145 | |
| 146 | da = ethosu_of_pa_to_da(rproc, pa, size); |
| 147 | if (da == (dma_addr_t)(-1)) { |
| 148 | dev_err(dev, "No mapping found for PA. pa=%llx, size=%zu", pa, |
| 149 | size); |
| 150 | |
| 151 | return -ENOMEM; |
| 152 | } |
| 153 | |
| 154 | va = devm_ioremap_wc(dev, pa, size); |
| 155 | if (!va) { |
| 156 | dev_err(dev, "Failed to remap address. pa=%llx, len=%zu", pa, |
| 157 | size); |
| 158 | |
| 159 | return -ENOMEM; |
| 160 | } |
| 161 | |
| 162 | mem = rproc_mem_entry_init(dev, va, pa, size, da, NULL, NULL, name); |
| 163 | if (!mem) |
| 164 | return -ENOMEM; |
| 165 | |
| 166 | dev_info(dev, "Add carveout mapping. dma=%llx, da=%x, va=%p, len=%zu", |
| 167 | mem->dma, mem->da, mem->va, mem->len); |
| 168 | |
| 169 | rproc_add_carveout(rproc, mem); |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | static int ethosu_rproc_prepare(struct rproc *rproc) |
| 175 | { |
| 176 | struct device *dev = rproc->dev.parent; |
| 177 | struct device_node *np = dev->of_node; |
| 178 | struct of_phandle_iterator it; |
| 179 | struct resource res; |
| 180 | int i; |
| 181 | int ret; |
| 182 | |
| 183 | dev_info(dev, "Preparing Ethos-U"); |
| 184 | |
| 185 | /* Add carveout for each 'reg' device tree entry */ |
| 186 | for (i = 0; of_address_to_resource(np, i, &res) == 0; i++) { |
| 187 | dev_info(dev, "Found resource. start=%llx, size=%llx", |
| 188 | res.start, resource_size(&res)); |
| 189 | |
| 190 | ret = ethosu_add_carveout(rproc, res.start, |
| 191 | resource_size(&res), res.name); |
| 192 | if (ret) |
| 193 | return ret; |
| 194 | } |
| 195 | |
| 196 | of_phandle_iterator_init(&it, np, "memory-region", NULL, 0); |
| 197 | while (of_phandle_iterator_next(&it) == 0) { |
| 198 | struct reserved_mem *res_mem = of_reserved_mem_lookup(it.node); |
| 199 | |
| 200 | if (!res_mem) { |
| 201 | dev_err(dev, "Failed to look up memory region. node=%p", |
| 202 | it.node); |
| 203 | |
| 204 | return -EINVAL; |
| 205 | } |
| 206 | |
| 207 | dev_info(dev, |
| 208 | "Found memory region. pa=%llx, size=%llu, name=%s", |
| 209 | res_mem->base, res_mem->size, it.node->name); |
| 210 | |
| 211 | ret = ethosu_add_carveout(rproc, res_mem->base, res_mem->size, |
| 212 | it.node->name); |
| 213 | if (ret) |
| 214 | return ret; |
| 215 | } |
| 216 | |
| 217 | return 0; |
| 218 | } |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 219 | |
| 220 | static int ethosu_rproc_start(struct rproc *rproc) |
| 221 | { |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 222 | struct ethosu_rproc *erproc = (struct ethosu_rproc *)rproc->priv; |
| 223 | struct device *dev = erproc->dev; |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 224 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 225 | dev_info(dev, "Starting up Ethos-U subsystem CPU"); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 226 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 227 | return reset_control_deassert(erproc->rstc); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static int ethosu_rproc_stop(struct rproc *rproc) |
| 231 | { |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 232 | struct ethosu_rproc *erproc = (struct ethosu_rproc *)rproc->priv; |
| 233 | struct device *dev = erproc->dev; |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 234 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 235 | dev_info(dev, "Stopping Ethos-U subsystem CPU"); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 236 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 237 | return reset_control_assert(erproc->rstc); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static void ethosu_rproc_kick(struct rproc *rproc, |
| 241 | int vqid) |
| 242 | { |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 243 | struct ethosu_rproc *erproc = (struct ethosu_rproc *)rproc->priv; |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 244 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 245 | dev_dbg(&rproc->dev, "Kicking Ethos-U remoteproc vqid: %d!", vqid); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 246 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 247 | mbox_send_message(erproc->ch_tx, (void *)&vqid); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | static const struct rproc_ops ethosu_rproc_ops = { |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 251 | .prepare = ðosu_rproc_prepare, |
| 252 | .start = ðosu_rproc_start, |
| 253 | .stop = ðosu_rproc_stop, |
| 254 | .kick = ðosu_rproc_kick, |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 255 | }; |
| 256 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 257 | static int ethosu_mailbox_init(struct ethosu_rproc *erproc) |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 258 | { |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 259 | struct device *dev = erproc->dev; |
| 260 | struct mbox_client *cl = &erproc->mbox_client; |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 261 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 262 | INIT_WORK(&erproc->work, ethosu_mbox_bottom); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 263 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 264 | erproc->wq = create_singlethread_workqueue("ethosu_rproc_wq"); |
| 265 | if (!erproc->wq) { |
| 266 | dev_err(dev, "Failed to create work queue"); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 267 | |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 271 | cl->dev = dev; |
| 272 | cl->rx_callback = ethosu_mbox_top; |
| 273 | cl->tx_prepare = NULL; |
| 274 | cl->tx_done = NULL; |
| 275 | cl->tx_block = true; |
| 276 | cl->knows_txdone = false; |
| 277 | cl->tx_tout = 500; |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 278 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 279 | erproc->ch_rx = mbox_request_channel_byname(cl, "rx"); |
| 280 | if (IS_ERR(erproc->ch_rx)) { |
| 281 | dev_err(dev, "Failed to request mbox chan rx"); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 282 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 283 | return PTR_ERR(erproc->ch_rx); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 284 | } |
| 285 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 286 | erproc->ch_tx = mbox_request_channel_byname(cl, "tx"); |
| 287 | if (IS_ERR(erproc->ch_tx)) { |
| 288 | dev_info(dev, "Using same channel for RX and TX"); |
| 289 | erproc->ch_tx = erproc->ch_rx; |
| 290 | } |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 291 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 292 | return 0; |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | static const struct of_device_id ethosu_rproc_match[] = { |
Per Åstrand | 9f36f2e | 2021-09-30 09:57:34 +0200 | [diff] [blame] | 296 | { .compatible = "arm,ethosu-rproc" }, |
Per Åstrand | b9248a4 | 2022-05-18 16:05:16 +0200 | [diff] [blame] | 297 | { /* sentinel */ }, |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | static int ethosu_rproc_probe(struct platform_device *pdev) |
| 301 | { |
| 302 | struct device *dev = &pdev->dev; |
| 303 | struct device_node *np = dev->of_node; |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 304 | struct ethosu_rproc *erproc; |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 305 | struct rproc *rproc; |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 306 | int ret; |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 307 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 308 | /* map the first 'memory-region' for DMA-mapping */ |
| 309 | ret = of_reserved_mem_device_init(dev); |
| 310 | if (ret) |
| 311 | return ret; |
| 312 | |
| 313 | dma_set_mask_and_coherent(dev, DMA_BIT_MASK(DMA_ADDR_BITS)); |
| 314 | |
| 315 | rproc = devm_rproc_alloc(dev, np->name, ðosu_rproc_ops, |
| 316 | fw_filename_param, |
| 317 | sizeof(*erproc)); |
| 318 | if (!rproc) |
| 319 | return -ENOMEM; |
| 320 | |
| 321 | platform_set_drvdata(pdev, rproc); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 322 | |
| 323 | /* Configure rproc */ |
| 324 | rproc->has_iommu = false; |
| 325 | rproc->auto_boot = auto_boot; |
| 326 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 327 | /* Configure Ethos-U rproc */ |
| 328 | erproc = rproc->priv; |
| 329 | erproc->dev = dev; |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 330 | |
| 331 | /* Get the reset handler for the subsystem */ |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 332 | erproc->rstc = devm_reset_control_get_exclusive_by_index(dev, 0); |
| 333 | if (IS_ERR(erproc->rstc)) { |
| 334 | dev_err(&pdev->dev, "Failed to get reset controller."); |
| 335 | |
| 336 | return PTR_ERR(erproc->rstc); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 339 | /* Allocate and initialize mailbox client */ |
| 340 | ret = ethosu_mailbox_init(erproc); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 341 | if (ret) |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 342 | return ret; |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 343 | |
| 344 | ret = rproc_add(rproc); |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 345 | if (ret) { |
| 346 | dev_err(dev, "Failed to add rproc"); |
| 347 | goto free_mbox; |
| 348 | } |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 349 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 350 | return 0; |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 351 | |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 352 | free_mbox: |
| 353 | if (erproc->wq) |
| 354 | destroy_workqueue(erproc->wq); |
| 355 | |
| 356 | mbox_free_channel(erproc->ch_rx); |
| 357 | |
| 358 | if (erproc->ch_tx != erproc->ch_rx) |
| 359 | mbox_free_channel(erproc->ch_tx); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 360 | |
| 361 | return ret; |
| 362 | } |
| 363 | |
| 364 | static int ethosu_rproc_remove(struct platform_device *pdev) |
| 365 | { |
| 366 | struct rproc *rproc = platform_get_drvdata(pdev); |
Kristofer Jonsson | a70bfde | 2023-01-12 10:00:03 +0100 | [diff] [blame] | 367 | struct ethosu_rproc *erproc = rproc->priv; |
| 368 | |
| 369 | if (erproc->wq) |
| 370 | destroy_workqueue(erproc->wq); |
| 371 | |
| 372 | if (erproc->ch_tx != erproc->ch_rx) |
| 373 | mbox_free_channel(erproc->ch_tx); |
| 374 | |
| 375 | mbox_free_channel(erproc->ch_rx); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 376 | |
| 377 | rproc_del(rproc); |
Per Åstrand | 2cd5397 | 2021-04-12 13:46:04 +0200 | [diff] [blame] | 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | static struct platform_driver ethosu_rproc_driver = { |
| 383 | .probe = ethosu_rproc_probe, |
| 384 | .remove = ethosu_rproc_remove, |
| 385 | .driver = { |
| 386 | .name = "ethosu-rproc", |
| 387 | .of_match_table = of_match_ptr(ethosu_rproc_match), |
| 388 | }, |
| 389 | }; |
| 390 | |
| 391 | module_platform_driver(ethosu_rproc_driver); |
| 392 | |
| 393 | MODULE_LICENSE("GPL v2"); |
| 394 | MODULE_AUTHOR("Arm Ltd"); |
| 395 | MODULE_DESCRIPTION("Arm Ethos-U NPU RemoteProc Driver"); |
| 396 | MODULE_VERSION(ETHOSU_RPROC_DRIVER_VERSION); |