Lines Matching +full:host1x +full:- +full:class
1 // SPDX-License-Identifier: GPL-2.0-only
2 // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
8 #include <linux/dma-mapping.h>
15 #include "tegra-se.h"
21 kref_get(&cmdbuf->ref); in tegra_se_cmdbuf_get()
30 dma_free_attrs(cmdbuf->dev, cmdbuf->size, cmdbuf->addr, in tegra_se_cmdbuf_release()
31 cmdbuf->iova, 0); in tegra_se_cmdbuf_release()
40 kref_put(&cmdbuf->ref, tegra_se_cmdbuf_release); in tegra_se_cmdbuf_put()
52 return ERR_PTR(-ENOMEM); in tegra_se_cmdbuf_pin()
54 kref_init(&map->ref); in tegra_se_cmdbuf_pin()
55 map->bo = host1x_bo_get(bo); in tegra_se_cmdbuf_pin()
56 map->direction = direction; in tegra_se_cmdbuf_pin()
57 map->dev = dev; in tegra_se_cmdbuf_pin()
59 map->sgt = kzalloc(sizeof(*map->sgt), GFP_KERNEL); in tegra_se_cmdbuf_pin()
60 if (!map->sgt) { in tegra_se_cmdbuf_pin()
61 err = -ENOMEM; in tegra_se_cmdbuf_pin()
65 err = dma_get_sgtable(dev, map->sgt, cmdbuf->addr, in tegra_se_cmdbuf_pin()
66 cmdbuf->iova, cmdbuf->words * 4); in tegra_se_cmdbuf_pin()
70 err = dma_map_sgtable(dev, map->sgt, direction, 0); in tegra_se_cmdbuf_pin()
74 map->phys = sg_dma_address(map->sgt->sgl); in tegra_se_cmdbuf_pin()
75 map->size = cmdbuf->words * 4; in tegra_se_cmdbuf_pin()
76 map->chunks = err; in tegra_se_cmdbuf_pin()
81 sg_free_table(map->sgt); in tegra_se_cmdbuf_pin()
82 kfree(map->sgt); in tegra_se_cmdbuf_pin()
93 dma_unmap_sgtable(map->dev, map->sgt, map->direction, 0); in tegra_se_cmdbuf_unpin()
94 sg_free_table(map->sgt); in tegra_se_cmdbuf_unpin()
95 kfree(map->sgt); in tegra_se_cmdbuf_unpin()
96 host1x_bo_put(map->bo); in tegra_se_cmdbuf_unpin()
105 return cmdbuf->addr; in tegra_se_cmdbuf_mmap()
124 struct device *dev = se->dev->parent; in tegra_se_host1x_bo_alloc()
130 cmdbuf->addr = dma_alloc_attrs(dev, size, &cmdbuf->iova, in tegra_se_host1x_bo_alloc()
132 if (!cmdbuf->addr) in tegra_se_host1x_bo_alloc()
135 cmdbuf->size = size; in tegra_se_host1x_bo_alloc()
136 cmdbuf->dev = dev; in tegra_se_host1x_bo_alloc()
138 host1x_bo_init(&cmdbuf->bo, &tegra_se_cmdbuf_ops); in tegra_se_host1x_bo_alloc()
139 kref_init(&cmdbuf->ref); in tegra_se_host1x_bo_alloc()
149 job = host1x_job_alloc(se->channel, 1, 0, true); in tegra_se_host1x_submit()
151 dev_err(se->dev, "failed to allocate host1x job\n"); in tegra_se_host1x_submit()
152 return -ENOMEM; in tegra_se_host1x_submit()
155 job->syncpt = host1x_syncpt_get(se->syncpt); in tegra_se_host1x_submit()
156 job->syncpt_incrs = 1; in tegra_se_host1x_submit()
157 job->client = &se->client; in tegra_se_host1x_submit()
158 job->class = se->client.class; in tegra_se_host1x_submit()
159 job->serialize = true; in tegra_se_host1x_submit()
160 job->engine_fallback_streamid = se->stream_id; in tegra_se_host1x_submit()
161 job->engine_streamid_offset = SE_STREAM_ID; in tegra_se_host1x_submit()
163 se->cmdbuf->words = size; in tegra_se_host1x_submit()
165 host1x_job_add_gather(job, &se->cmdbuf->bo, size, 0); in tegra_se_host1x_submit()
167 ret = host1x_job_pin(job, se->dev); in tegra_se_host1x_submit()
169 dev_err(se->dev, "failed to pin host1x job\n"); in tegra_se_host1x_submit()
175 dev_err(se->dev, "failed to submit host1x job\n"); in tegra_se_host1x_submit()
179 ret = host1x_syncpt_wait(job->syncpt, job->syncpt_end, in tegra_se_host1x_submit()
182 dev_err(se->dev, "host1x job timed out\n"); in tegra_se_host1x_submit()
202 se->channel = host1x_channel_request(&se->client); in tegra_se_client_init()
203 if (!se->channel) { in tegra_se_client_init()
204 dev_err(se->dev, "host1x channel map failed\n"); in tegra_se_client_init()
205 return -ENODEV; in tegra_se_client_init()
208 se->syncpt = host1x_syncpt_request(&se->client, 0); in tegra_se_client_init()
209 if (!se->syncpt) { in tegra_se_client_init()
210 dev_err(se->dev, "host1x syncpt allocation failed\n"); in tegra_se_client_init()
211 ret = -EINVAL; in tegra_se_client_init()
215 se->syncpt_id = host1x_syncpt_id(se->syncpt); in tegra_se_client_init()
217 se->cmdbuf = tegra_se_host1x_bo_alloc(se, SZ_4K); in tegra_se_client_init()
218 if (!se->cmdbuf) { in tegra_se_client_init()
219 ret = -ENOMEM; in tegra_se_client_init()
223 ret = se->hw->init_alg(se); in tegra_se_client_init()
225 dev_err(se->dev, "failed to register algorithms\n"); in tegra_se_client_init()
232 tegra_se_cmdbuf_put(&se->cmdbuf->bo); in tegra_se_client_init()
234 host1x_syncpt_put(se->syncpt); in tegra_se_client_init()
236 host1x_channel_put(se->channel); in tegra_se_client_init()
245 se->hw->deinit_alg(se); in tegra_se_client_deinit()
246 tegra_se_cmdbuf_put(&se->cmdbuf->bo); in tegra_se_client_deinit()
247 host1x_syncpt_put(se->syncpt); in tegra_se_client_deinit()
248 host1x_channel_put(se->channel); in tegra_se_client_deinit()
260 INIT_LIST_HEAD(&se->client.list); in tegra_se_host1x_register()
261 se->client.dev = se->dev; in tegra_se_host1x_register()
262 se->client.ops = &tegra_se_client_ops; in tegra_se_host1x_register()
263 se->client.class = se->hw->host1x_class; in tegra_se_host1x_register()
264 se->client.num_syncpts = 1; in tegra_se_host1x_register()
266 host1x_client_register(&se->client); in tegra_se_host1x_register()
273 struct device *dev = &pdev->dev; in tegra_se_probe()
279 return -ENOMEM; in tegra_se_probe()
281 se->dev = dev; in tegra_se_probe()
282 se->owner = TEGRA_GPSE_ID; in tegra_se_probe()
283 se->hw = device_get_match_data(&pdev->dev); in tegra_se_probe()
285 se->base = devm_platform_ioremap_resource(pdev, 0); in tegra_se_probe()
286 if (IS_ERR(se->base)) in tegra_se_probe()
287 return PTR_ERR(se->base); in tegra_se_probe()
292 se->clk = devm_clk_get_enabled(se->dev, NULL); in tegra_se_probe()
293 if (IS_ERR(se->clk)) in tegra_se_probe()
294 return dev_err_probe(dev, PTR_ERR(se->clk), in tegra_se_probe()
297 if (!tegra_dev_iommu_get_stream_id(dev, &se->stream_id)) in tegra_se_probe()
298 return dev_err_probe(dev, -ENODEV, in tegra_se_probe()
301 writel(se->stream_id, se->base + SE_STREAM_ID); in tegra_se_probe()
303 se->engine = crypto_engine_alloc_init(dev, 0); in tegra_se_probe()
304 if (!se->engine) in tegra_se_probe()
305 return dev_err_probe(dev, -ENOMEM, "failed to init crypto engine\n"); in tegra_se_probe()
307 ret = crypto_engine_start(se->engine); in tegra_se_probe()
309 crypto_engine_exit(se->engine); in tegra_se_probe()
315 crypto_engine_stop(se->engine); in tegra_se_probe()
316 crypto_engine_exit(se->engine); in tegra_se_probe()
317 return dev_err_probe(dev, ret, "failed to init host1x params\n"); in tegra_se_probe()
327 crypto_engine_stop(se->engine); in tegra_se_remove()
328 crypto_engine_exit(se->engine); in tegra_se_remove()
329 host1x_client_unregister(&se->client); in tegra_se_remove()
374 .compatible = "nvidia,tegra234-se-aes",
377 .compatible = "nvidia,tegra234-se-hash",
386 .name = "tegra-se",
407 .name = "tegra-se-host1x",