| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ttm_bus_dma.c,v 1.4 2017/03/09 07:50:50 maya Exp $ */ | | 1 | /* $NetBSD: ttm_bus_dma.c,v 1.5 2017/03/09 07:55:23 maya Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2014 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2014 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Taylor R. Campbell. | | 8 | * by Taylor R. Campbell. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -20,27 +20,27 @@ | | | @@ -20,27 +20,27 @@ |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: ttm_bus_dma.c,v 1.4 2017/03/09 07:50:50 maya Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: ttm_bus_dma.c,v 1.5 2017/03/09 07:55:23 maya Exp $"); |
34 | | | 34 | |
35 | #include <sys/bus.h> | | 35 | #include <sys/bus.h> |
36 | | | 36 | |
37 | #include <uvm/uvm_extern.h> | | 37 | #include <uvm/uvm_extern.h> |
38 | | | 38 | |
39 | #include <drm/bus_dma_hacks.h> | | 39 | #include <drm/bus_dma_hacks.h> |
40 | #include <ttm/ttm_bo_driver.h> | | 40 | #include <ttm/ttm_bo_driver.h> |
41 | #include <ttm/ttm_page_alloc.h> | | 41 | #include <ttm/ttm_page_alloc.h> |
42 | | | 42 | |
43 | /* | | 43 | /* |
44 | * ttm_bus_dma_populate(ttm_dma) | | 44 | * ttm_bus_dma_populate(ttm_dma) |
45 | * | | 45 | * |
46 | * If ttm_dma is not already populated, wire its pages and load | | 46 | * If ttm_dma is not already populated, wire its pages and load |
| @@ -76,27 +76,29 @@ ttm_bus_dma_populate(struct ttm_dma_tt * | | | @@ -76,27 +76,29 @@ ttm_bus_dma_populate(struct ttm_dma_tt * |
76 | ttm_dma->dma_address, &ttm_dma->ttm.pglist, | | 76 | ttm_dma->dma_address, &ttm_dma->ttm.pglist, |
77 | (ttm_dma->ttm.num_pages << PAGE_SHIFT), BUS_DMA_NOWAIT); | | 77 | (ttm_dma->ttm.num_pages << PAGE_SHIFT), BUS_DMA_NOWAIT); |
78 | if (ret) | | 78 | if (ret) |
79 | goto fail1; | | 79 | goto fail1; |
80 | | | 80 | |
81 | /* Mark it wired. */ | | 81 | /* Mark it wired. */ |
82 | ttm_dma->ttm.page_flags &= ~TTM_PAGE_FLAG_SWAPPED; | | 82 | ttm_dma->ttm.page_flags &= ~TTM_PAGE_FLAG_SWAPPED; |
83 | | | 83 | |
84 | /* Success! */ | | 84 | /* Success! */ |
85 | return 0; | | 85 | return 0; |
86 | | | 86 | |
87 | fail2: __unused | | 87 | fail2: __unused |
88 | bus_dmamap_unload(ttm_dma->ttm.bdev->dmat, ttm_dma->dma_address); | | 88 | bus_dmamap_unload(ttm_dma->ttm.bdev->dmat, ttm_dma->dma_address); |
89 | fail1: ttm_tt_unwire(&ttm_dma->ttm); | | 89 | fail1: KASSERT(ttm->state == tt_unbound); |
| | | 90 | ttm_tt_unwire(&ttm_dma->ttm); |
| | | 91 | ttm->state = tt_unpopulated; |
90 | fail0: KASSERT(ret); | | 92 | fail0: KASSERT(ret); |
91 | return ret; | | 93 | return ret; |
92 | } | | 94 | } |
93 | | | 95 | |
94 | static void | | 96 | static void |
95 | ttm_bus_dma_put(struct ttm_dma_tt *ttm_dma, int flags) | | 97 | ttm_bus_dma_put(struct ttm_dma_tt *ttm_dma, int flags) |
96 | { | | 98 | { |
97 | struct uvm_object *const uobj = ttm_dma->ttm.swap_storage; | | 99 | struct uvm_object *const uobj = ttm_dma->ttm.swap_storage; |
98 | const size_t size = (ttm_dma->ttm.num_pages << PAGE_SHIFT); | | 100 | const size_t size = (ttm_dma->ttm.num_pages << PAGE_SHIFT); |
99 | | | 101 | |
100 | /* | | 102 | /* |
101 | * Can't be tt_bound -- still in use and needs to be removed | | 103 | * Can't be tt_bound -- still in use and needs to be removed |
102 | * from GPU page tables. Can't be tt_unpopulated -- if it | | 104 | * from GPU page tables. Can't be tt_unpopulated -- if it |