Thu Mar 9 08:27:18 2017 UTC ()
Clarify ttm state transitions tt_unpopulated<->tt_unbound<->tt_bound.
Assert it, too, and don't handle other cases.

We can add the assertion to ttm_agp_tt_unpopulate because it is called by
{nouveau,radeon}_ttm_tt_unpopulate, which is generically called
ttm_tt_unpopulate.

And the sole caller to ttm_tt_unpopulate (ttm_tt_destroy) only does so if the
state is unbound. the other caller is in a !NetBSD block.

We can add the assertion to ttm_agp_tt_populate and avoid handling the
!unpopulated case because the sole callers are {nouveau,radeon}_ttm_tt_populate
both of which return early in the !unpopulated case.

We can change the assertion on ttm_tt_wire because it is solely called by
ttm_bus_dma_populate, which already asserts that it is the unpopulated case.

from riastradh


(maya)
diff -r1.8 -r1.9 src/sys/external/bsd/drm2/dist/drm/ttm/ttm_tt.c
diff -r1.5 -r1.6 src/sys/external/bsd/drm2/ttm/ttm_agp_backend.c
diff -r1.6 -r1.7 src/sys/external/bsd/drm2/ttm/ttm_bus_dma.c

cvs diff -r1.8 -r1.9 src/sys/external/bsd/drm2/dist/drm/ttm/ttm_tt.c (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/dist/drm/ttm/ttm_tt.c 2016/12/24 15:46:50 1.8
+++ src/sys/external/bsd/drm2/dist/drm/ttm/ttm_tt.c 2017/03/09 08:27:18 1.9
@@ -350,41 +350,40 @@ int ttm_tt_bind(struct ttm_tt *ttm, stru @@ -350,41 +350,40 @@ int ttm_tt_bind(struct ttm_tt *ttm, stru
350 return ret; 350 return ret;
351 351
352 ttm->state = tt_bound; 352 ttm->state = tt_bound;
353 353
354 return 0; 354 return 0;
355} 355}
356EXPORT_SYMBOL(ttm_tt_bind); 356EXPORT_SYMBOL(ttm_tt_bind);
357 357
358#ifdef __NetBSD__ 358#ifdef __NetBSD__
359/* 359/*
360 * ttm_tt_wire(ttm) 360 * ttm_tt_wire(ttm)
361 * 361 *
362 * Wire the uvm pages of ttm and fill the ttm page array. ttm 362 * Wire the uvm pages of ttm and fill the ttm page array. ttm
363 * must be unpopulated or unbound, and must be marked swapped. 363 * must be unpopulated, and must be marked swapped. This does not
364 * This does not change either state -- the caller is expected to 364 * change either state -- the caller is expected to include it
365 * include it among other operations for such a state transition. 365 * among other operations for such a state transition.
366 */ 366 */
367int 367int
368ttm_tt_wire(struct ttm_tt *ttm) 368ttm_tt_wire(struct ttm_tt *ttm)
369{ 369{
370 struct uvm_object *uobj = ttm->swap_storage; 370 struct uvm_object *uobj = ttm->swap_storage;
371 struct vm_page *page; 371 struct vm_page *page;
372 unsigned i; 372 unsigned i;
373 int error; 373 int error;
374 374
375 KASSERTMSG((ttm->state == tt_unpopulated || ttm->state == tt_unbound), 375 KASSERTMSG((ttm->state == tt_unpopulated),
376 "ttm_tt %p must be unpopulated or unbound for wiring," 376 "ttm_tt %p must be unpopulated for wiring, but state=%d",
377 " but state=%d", 
378 ttm, (int)ttm->state); 377 ttm, (int)ttm->state);
379 KASSERT(ISSET(ttm->page_flags, TTM_PAGE_FLAG_SWAPPED)); 378 KASSERT(ISSET(ttm->page_flags, TTM_PAGE_FLAG_SWAPPED));
380 KASSERT(uobj != NULL); 379 KASSERT(uobj != NULL);
381 380
382 error = uvm_obj_wirepages(uobj, 0, (ttm->num_pages << PAGE_SHIFT), 381 error = uvm_obj_wirepages(uobj, 0, (ttm->num_pages << PAGE_SHIFT),
383 &ttm->pglist); 382 &ttm->pglist);
384 if (error) 383 if (error)
385 /* XXX errno NetBSD->Linux */ 384 /* XXX errno NetBSD->Linux */
386 return -error; 385 return -error;
387 386
388 i = 0; 387 i = 0;
389 TAILQ_FOREACH(page, &ttm->pglist, pageq.queue) { 388 TAILQ_FOREACH(page, &ttm->pglist, pageq.queue) {
390 KASSERT(i < ttm->num_pages); 389 KASSERT(i < ttm->num_pages);

cvs diff -r1.5 -r1.6 src/sys/external/bsd/drm2/ttm/ttm_agp_backend.c (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/ttm/ttm_agp_backend.c 2015/10/17 21:05:57 1.5
+++ src/sys/external/bsd/drm2/ttm/ttm_agp_backend.c 2017/03/09 08:27:18 1.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ttm_agp_backend.c,v 1.5 2015/10/17 21:05:57 jmcneill Exp $ */ 1/* $NetBSD: ttm_agp_backend.c,v 1.6 2017/03/09 08:27:18 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_agp_backend.c,v 1.5 2015/10/17 21:05:57 jmcneill Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: ttm_agp_backend.c,v 1.6 2017/03/09 08:27:18 maya Exp $");
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/kmem.h> 36#include <sys/kmem.h>
37 37
38#include <dev/pci/pcireg.h> 38#include <dev/pci/pcireg.h>
39#include <dev/pci/pcivar.h> 39#include <dev/pci/pcivar.h>
40#include <dev/pci/agpvar.h> 40#include <dev/pci/agpvar.h>
41 41
42#include <ttm/ttm_bo_driver.h> 42#include <ttm/ttm_bo_driver.h>
43#include <ttm/ttm_page_alloc.h> 43#include <ttm/ttm_page_alloc.h>
44 44
45#if __OS_HAS_AGP 45#if __OS_HAS_AGP
46 46
@@ -68,36 +68,39 @@ ttm_agp_tt_create(struct ttm_bo_device * @@ -68,36 +68,39 @@ ttm_agp_tt_create(struct ttm_bo_device *
68 goto fail; 68 goto fail;
69 69
70 /* Success! */ 70 /* Success! */
71 return &ttm_agp->ttm_dma.ttm; 71 return &ttm_agp->ttm_dma.ttm;
72 72
73fail: kmem_free(ttm_agp, sizeof(*ttm_agp)); 73fail: kmem_free(ttm_agp, sizeof(*ttm_agp));
74 return NULL; 74 return NULL;
75} 75}
76 76
77int 77int
78ttm_agp_tt_populate(struct ttm_tt *ttm) 78ttm_agp_tt_populate(struct ttm_tt *ttm)
79{ 79{
80 80
81 if (ttm->state != tt_unpopulated) 81 KASSERTMSG((ttm->state == tt_unpopulated),
82 return 0; 82 "ttm_agp_tt_populate: ttm %p state is not tt_unpopulated: %d",
83 83 ttm, (int)ttm->state);
84 return ttm_bus_dma_populate(container_of(ttm, struct ttm_dma_tt, ttm)); 84 return ttm_bus_dma_populate(container_of(ttm, struct ttm_dma_tt, ttm));
85} 85}
86 86
87void 87void
88ttm_agp_tt_unpopulate(struct ttm_tt *ttm) 88ttm_agp_tt_unpopulate(struct ttm_tt *ttm)
89{ 89{
90 90
 91 KASSERTMSG((ttm->state == tt_unbound),
 92 "ttm_agp_tt_unpopulate: ttm %p state is not tt_unbound: %d",
 93 ttm, (int)ttm->state);
91 ttm_bus_dma_unpopulate(container_of(ttm, struct ttm_dma_tt, ttm)); 94 ttm_bus_dma_unpopulate(container_of(ttm, struct ttm_dma_tt, ttm));
92} 95}
93 96
94static int 97static int
95ttm_agp_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem) 98ttm_agp_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
96{ 99{
97 struct ttm_agp *const ttm_agp = container_of(ttm, struct ttm_agp, 100 struct ttm_agp *const ttm_agp = container_of(ttm, struct ttm_agp,
98 ttm_dma.ttm); 101 ttm_dma.ttm);
99 struct agp_softc *const sc = ttm_agp->agp; 102 struct agp_softc *const sc = ttm_agp->agp;
100 struct drm_mm_node *const node = bo_mem->mm_node; 103 struct drm_mm_node *const node = bo_mem->mm_node;
101 const unsigned long agp_pgno = node->start; 104 const unsigned long agp_pgno = node->start;
102 unsigned i, j; 105 unsigned i, j;
103 int ret; 106 int ret;

cvs diff -r1.6 -r1.7 src/sys/external/bsd/drm2/ttm/ttm_bus_dma.c (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/ttm/ttm_bus_dma.c 2017/03/09 08:05:21 1.6
+++ src/sys/external/bsd/drm2/ttm/ttm_bus_dma.c 2017/03/09 08:27:18 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ttm_bus_dma.c,v 1.6 2017/03/09 08:05:21 maya Exp $ */ 1/* $NetBSD: ttm_bus_dma.c,v 1.7 2017/03/09 08:27:18 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,45 +20,45 @@ @@ -20,45 +20,45 @@
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.6 2017/03/09 08:05:21 maya Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: ttm_bus_dma.c,v 1.7 2017/03/09 08:27:18 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
47 * its DMA map. The wiring and loading are stable as long as the 47 * its DMA map. The wiring and loading are stable as long as the
48 * associated bo is reserved. 48 * associated bo is reserved.
49 * 49 *
50 * Transitions from tt_unpopulated or tt_unbound to tt_unbound. 50 * Transitions from tt_unpopulated to tt_unbound. Marks as wired,
51 * Marks as wired, a.k.a. !swapped. 51 * a.k.a. !swapped.
52 */ 52 */
53int 53int
54ttm_bus_dma_populate(struct ttm_dma_tt *ttm_dma) 54ttm_bus_dma_populate(struct ttm_dma_tt *ttm_dma)
55{ 55{
56 int ret; 56 int ret;
57 57
58 KASSERT(ttm_dma->ttm.state == tt_unpopulated); 58 KASSERT(ttm_dma->ttm.state == tt_unpopulated);
59 59
60 /* If it's unpopulated, it can't be swapped. */ 60 /* If it's unpopulated, it can't be swapped. */
61 KASSERT(!ISSET(ttm_dma->ttm.page_flags, TTM_PAGE_FLAG_SWAPPED)); 61 KASSERT(!ISSET(ttm_dma->ttm.page_flags, TTM_PAGE_FLAG_SWAPPED));
62 /* Pretend it is now, for the sake of ttm_tt_wire. */ 62 /* Pretend it is now, for the sake of ttm_tt_wire. */
63 ttm_dma->ttm.page_flags |= TTM_PAGE_FLAG_SWAPPED; 63 ttm_dma->ttm.page_flags |= TTM_PAGE_FLAG_SWAPPED;
64 64