| @@ -1,38 +1,38 @@ | | | @@ -1,38 +1,38 @@ |
1 | /* $NetBSD: nouveau_nvkm_subdev_mmu_mem.c,v 1.3 2021/12/19 10:51:58 riastradh Exp $ */ | | 1 | /* $NetBSD: nouveau_nvkm_subdev_mmu_mem.c,v 1.4 2021/12/19 11:06:12 riastradh Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright 2017 Red Hat Inc. | | 4 | * Copyright 2017 Red Hat Inc. |
5 | * | | 5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a | | 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
7 | * copy of this software and associated documentation files (the "Software"), | | 7 | * copy of this software and associated documentation files (the "Software"), |
8 | * to deal in the Software without restriction, including without limitation | | 8 | * to deal in the Software without restriction, including without limitation |
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | | 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
10 | * and/or sell copies of the Software, and to permit persons to whom the | | 10 | * and/or sell copies of the Software, and to permit persons to whom the |
11 | * Software is furnished to do so, subject to the following conditions: | | 11 | * Software is furnished to do so, subject to the following conditions: |
12 | * | | 12 | * |
13 | * The above copyright notice and this permission notice shall be included in | | 13 | * The above copyright notice and this permission notice shall be included in |
14 | * all copies or substantial portions of the Software. | | 14 | * all copies or substantial portions of the Software. |
15 | * | | 15 | * |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR | | 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | | 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | | 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
22 | * OTHER DEALINGS IN THE SOFTWARE. | | 22 | * OTHER DEALINGS IN THE SOFTWARE. |
23 | */ | | 23 | */ |
24 | #include <sys/cdefs.h> | | 24 | #include <sys/cdefs.h> |
25 | __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_mmu_mem.c,v 1.3 2021/12/19 10:51:58 riastradh Exp $"); | | 25 | __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_mmu_mem.c,v 1.4 2021/12/19 11:06:12 riastradh Exp $"); |
26 | | | 26 | |
27 | #define nvkm_mem(p) container_of((p), struct nvkm_mem, memory) | | 27 | #define nvkm_mem(p) container_of((p), struct nvkm_mem, memory) |
28 | #include "mem.h" | | 28 | #include "mem.h" |
29 | | | 29 | |
30 | #include <core/memory.h> | | 30 | #include <core/memory.h> |
31 | | | 31 | |
32 | #include <nvif/if000a.h> | | 32 | #include <nvif/if000a.h> |
33 | #include <nvif/unpack.h> | | 33 | #include <nvif/unpack.h> |
34 | | | 34 | |
35 | #include <linux/nbsd-namespace.h> | | 35 | #include <linux/nbsd-namespace.h> |
36 | | | 36 | |
37 | struct nvkm_mem { | | 37 | struct nvkm_mem { |
38 | struct nvkm_memory memory; | | 38 | struct nvkm_memory memory; |
| @@ -270,26 +270,27 @@ fail1: bus_dmamem_free(dmat, mem->mem, | | | @@ -270,26 +270,27 @@ fail1: bus_dmamem_free(dmat, mem->mem, |
270 | ret = -bus_dmamap_load_raw(dmat, mem->dmamap, mem->mem, mem->nseg, | | 270 | ret = -bus_dmamap_load_raw(dmat, mem->dmamap, mem->mem, mem->nseg, |
271 | size << PAGE_SHIFT, BUS_DMA_WAITOK); | | 271 | size << PAGE_SHIFT, BUS_DMA_WAITOK); |
272 | if (ret) { | | 272 | if (ret) { |
273 | fail2: __unused | | 273 | fail2: __unused |
274 | bus_dmamap_destroy(dmat, mem->dmamap); | | 274 | bus_dmamap_destroy(dmat, mem->dmamap); |
275 | goto fail1; | | 275 | goto fail1; |
276 | } | | 276 | } |
277 | mem->dma = kmem_zalloc(mem->dmamap->dm_nsegs * sizeof(mem->dma[0]), | | 277 | mem->dma = kmem_zalloc(mem->dmamap->dm_nsegs * sizeof(mem->dma[0]), |
278 | KM_SLEEP); | | 278 | KM_SLEEP); |
279 | for (unsigned i = 0; i < mem->dmamap->dm_nsegs; i++) { | | 279 | for (unsigned i = 0; i < mem->dmamap->dm_nsegs; i++) { |
280 | KASSERT(mem->dmamap->dm_segs[i].ds_len <= PAGE_SIZE); | | 280 | KASSERT(mem->dmamap->dm_segs[i].ds_len <= PAGE_SIZE); |
281 | mem->dma[i] = mem->dmamap->dm_segs[i].ds_addr; | | 281 | mem->dma[i] = mem->dmamap->dm_segs[i].ds_addr; |
282 | } | | 282 | } |
| | | 283 | mem->pages = size; |
283 | #else | | 284 | #else |
284 | if (!(mem->mem = kvmalloc_array(size, sizeof(*mem->mem), GFP_KERNEL))) | | 285 | if (!(mem->mem = kvmalloc_array(size, sizeof(*mem->mem), GFP_KERNEL))) |
285 | return -ENOMEM; | | 286 | return -ENOMEM; |
286 | if (!(mem->dma = kvmalloc_array(size, sizeof(*mem->dma), GFP_KERNEL))) | | 287 | if (!(mem->dma = kvmalloc_array(size, sizeof(*mem->dma), GFP_KERNEL))) |
287 | return -ENOMEM; | | 288 | return -ENOMEM; |
288 | | | 289 | |
289 | if (mmu->dma_bits > 32) | | 290 | if (mmu->dma_bits > 32) |
290 | gfp |= GFP_HIGHUSER; | | 291 | gfp |= GFP_HIGHUSER; |
291 | else | | 292 | else |
292 | gfp |= GFP_DMA32; | | 293 | gfp |= GFP_DMA32; |
293 | | | 294 | |
294 | for (mem->pages = 0; size; size--, mem->pages++) { | | 295 | for (mem->pages = 0; size; size--, mem->pages++) { |
295 | struct page *p = alloc_page(gfp); | | 296 | struct page *p = alloc_page(gfp); |