| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ttm_bus_dma.c,v 1.2 2016/04/24 04:26:12 riastradh Exp $ */ | | 1 | /* $NetBSD: ttm_bus_dma.c,v 1.3 2017/03/09 07:42:36 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.2 2016/04/24 04:26:12 riastradh Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: ttm_bus_dma.c,v 1.3 2017/03/09 07:42:36 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 |
| @@ -68,40 +68,40 @@ ttm_bus_dma_populate(struct ttm_dma_tt * | | | @@ -68,40 +68,40 @@ ttm_bus_dma_populate(struct ttm_dma_tt * |
68 | } else if (ttm_dma->ttm.state == tt_unpopulated) { | | 68 | } else if (ttm_dma->ttm.state == tt_unpopulated) { |
69 | /* If it's unpopulated, it can't be swapped. */ | | 69 | /* If it's unpopulated, it can't be swapped. */ |
70 | KASSERT(!ISSET(ttm_dma->ttm.page_flags, | | 70 | KASSERT(!ISSET(ttm_dma->ttm.page_flags, |
71 | TTM_PAGE_FLAG_SWAPPED)); | | 71 | TTM_PAGE_FLAG_SWAPPED)); |
72 | /* Pretend it is now, for the sake of ttm_tt_wire. */ | | 72 | /* Pretend it is now, for the sake of ttm_tt_wire. */ |
73 | ttm_dma->ttm.page_flags |= TTM_PAGE_FLAG_SWAPPED; | | 73 | ttm_dma->ttm.page_flags |= TTM_PAGE_FLAG_SWAPPED; |
74 | } | | 74 | } |
75 | | | 75 | |
76 | /* Wire the uvm pages and fill the ttm page array. */ | | 76 | /* Wire the uvm pages and fill the ttm page array. */ |
77 | ret = ttm_tt_wire(&ttm_dma->ttm); | | 77 | ret = ttm_tt_wire(&ttm_dma->ttm); |
78 | if (ret) | | 78 | if (ret) |
79 | goto fail0; | | 79 | goto fail0; |
80 | | | 80 | |
| | | 81 | /* Mark it populated but unbound. */ |
| | | 82 | ttm_dma->ttm.state = tt_unbound; |
| | | 83 | |
81 | /* Load the DMA map. */ | | 84 | /* Load the DMA map. */ |
82 | /* XXX errno NetBSD->Linux */ | | 85 | /* XXX errno NetBSD->Linux */ |
83 | ret = -bus_dmamap_load_pglist(ttm_dma->ttm.bdev->dmat, | | 86 | ret = -bus_dmamap_load_pglist(ttm_dma->ttm.bdev->dmat, |
84 | ttm_dma->dma_address, &ttm_dma->ttm.pglist, | | 87 | ttm_dma->dma_address, &ttm_dma->ttm.pglist, |
85 | (ttm_dma->ttm.num_pages << PAGE_SHIFT), BUS_DMA_NOWAIT); | | 88 | (ttm_dma->ttm.num_pages << PAGE_SHIFT), BUS_DMA_NOWAIT); |
86 | if (ret) | | 89 | if (ret) |
87 | goto fail1; | | 90 | goto fail1; |
88 | | | 91 | |
89 | /* Mark it wired. */ | | 92 | /* Mark it wired. */ |
90 | ttm_dma->ttm.page_flags &= ~TTM_PAGE_FLAG_SWAPPED; | | 93 | ttm_dma->ttm.page_flags &= ~TTM_PAGE_FLAG_SWAPPED; |
91 | | | 94 | |
92 | /* Mark it populated but unbound. */ | | | |
93 | ttm_dma->ttm.state = tt_unbound; | | | |
94 | | | | |
95 | /* Success! */ | | 95 | /* Success! */ |
96 | return 0; | | 96 | return 0; |
97 | | | 97 | |
98 | fail2: __unused | | 98 | fail2: __unused |
99 | bus_dmamap_unload(ttm_dma->ttm.bdev->dmat, ttm_dma->dma_address); | | 99 | bus_dmamap_unload(ttm_dma->ttm.bdev->dmat, ttm_dma->dma_address); |
100 | fail1: ttm_tt_unwire(&ttm_dma->ttm); | | 100 | fail1: ttm_tt_unwire(&ttm_dma->ttm); |
101 | fail0: KASSERT(ret); | | 101 | fail0: KASSERT(ret); |
102 | return ret; | | 102 | return ret; |
103 | } | | 103 | } |
104 | | | 104 | |
105 | static void | | 105 | static void |
106 | ttm_bus_dma_put(struct ttm_dma_tt *ttm_dma, int flags) | | 106 | ttm_bus_dma_put(struct ttm_dma_tt *ttm_dma, int flags) |
107 | { | | 107 | { |