Line data Source code
1 : /**************************************************************************
2 : *
3 : * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
4 : * All Rights Reserved.
5 : *
6 : * Permission is hereby granted, free of charge, to any person obtaining a
7 : * copy of this software and associated documentation files (the
8 : * "Software"), to deal in the Software without restriction, including
9 : * without limitation the rights to use, copy, modify, merge, publish,
10 : * distribute, sub license, and/or sell copies of the Software, and to
11 : * permit persons to whom the Software is furnished to do so, subject to
12 : * the following conditions:
13 : *
14 : * The above copyright notice and this permission notice (including the
15 : * next paragraph) shall be included in all copies or substantial portions
16 : * of the Software.
17 : *
18 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 : * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 : * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 : * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 : * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 : * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 : *
26 : **************************************************************************/
27 : /*
28 : * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29 : * Keith Packard.
30 : */
31 :
32 : #define pr_fmt(fmt) "[TTM] " fmt
33 :
34 : #include <dev/pci/drm/drmP.h>
35 : #include <dev/pci/drm/ttm/ttm_module.h>
36 : #include <dev/pci/drm/ttm/ttm_bo_driver.h>
37 : #include <dev/pci/drm/ttm/ttm_page_alloc.h>
38 : #ifdef TTM_HAS_AGP
39 : #include <dev/pci/drm/ttm/ttm_placement.h>
40 :
41 : struct ttm_agp_backend {
42 : struct ttm_tt ttm;
43 : int bound;
44 : bus_addr_t addr;
45 : struct drm_agp_head *agp;
46 : };
47 :
48 0 : static int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
49 : {
50 0 : struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
51 0 : struct drm_mm_node *node = bo_mem->mm_node;
52 0 : struct agp_softc *sc = agp_be->agp->agpdev;
53 : bus_addr_t addr;
54 : // int cached = (bo_mem->placement & TTM_PL_FLAG_CACHED);
55 : unsigned i;
56 :
57 0 : addr = sc->sc_apaddr + (node->start << PAGE_SHIFT);
58 0 : for (i = 0; i < ttm->num_pages; i++) {
59 0 : struct vm_page *page = ttm->pages[i];
60 :
61 0 : if (!page)
62 0 : page = ttm->dummy_read_page;
63 :
64 0 : sc->sc_methods->bind_page(sc->sc_chipc, addr, VM_PAGE_TO_PHYS(page), 0);
65 0 : addr += PAGE_SIZE;
66 : }
67 0 : agp_flush_cache();
68 0 : sc->sc_methods->flush_tlb(sc->sc_chipc);
69 0 : agp_be->addr = sc->sc_apaddr + (node->start << PAGE_SHIFT);
70 0 : agp_be->bound = 1;
71 :
72 0 : return 0;
73 : }
74 :
75 0 : static int ttm_agp_unbind(struct ttm_tt *ttm)
76 : {
77 0 : struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
78 0 : struct agp_softc *sc = agp_be->agp->agpdev;
79 : bus_addr_t addr;
80 : unsigned i;
81 :
82 0 : if (agp_be->bound) {
83 0 : addr = agp_be->addr;
84 0 : for (i = 0; i < ttm->num_pages; i++) {
85 0 : sc->sc_methods->unbind_page(sc->sc_chipc, addr);
86 0 : addr += PAGE_SIZE;
87 : }
88 0 : agp_flush_cache();
89 0 : sc->sc_methods->flush_tlb(sc->sc_chipc);
90 0 : agp_be->bound = 0;
91 0 : }
92 0 : return 0;
93 : }
94 :
95 0 : static void ttm_agp_destroy(struct ttm_tt *ttm)
96 : {
97 0 : struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
98 :
99 0 : if (agp_be->bound)
100 0 : ttm_agp_unbind(ttm);
101 0 : ttm_tt_fini(ttm);
102 0 : kfree(agp_be);
103 0 : }
104 :
105 : static struct ttm_backend_func ttm_agp_func = {
106 : .bind = ttm_agp_bind,
107 : .unbind = ttm_agp_unbind,
108 : .destroy = ttm_agp_destroy,
109 : };
110 :
111 0 : struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device *bdev,
112 : struct drm_agp_head *agp,
113 : unsigned long size, uint32_t page_flags,
114 : struct vm_page *dummy_read_page)
115 : {
116 : struct ttm_agp_backend *agp_be;
117 :
118 0 : agp_be = kmalloc(sizeof(*agp_be), GFP_KERNEL);
119 0 : if (!agp_be)
120 0 : return NULL;
121 :
122 0 : agp_be->bound = 0;
123 0 : agp_be->agp = agp;
124 0 : agp_be->ttm.func = &ttm_agp_func;
125 :
126 0 : if (ttm_tt_init(&agp_be->ttm, bdev, size, page_flags, dummy_read_page)) {
127 0 : return NULL;
128 : }
129 :
130 0 : return &agp_be->ttm;
131 0 : }
132 : EXPORT_SYMBOL(ttm_agp_tt_create);
133 :
134 0 : int ttm_agp_tt_populate(struct ttm_tt *ttm)
135 : {
136 0 : if (ttm->state != tt_unpopulated)
137 0 : return 0;
138 :
139 0 : return ttm_pool_populate(ttm);
140 0 : }
141 : EXPORT_SYMBOL(ttm_agp_tt_populate);
142 :
143 0 : void ttm_agp_tt_unpopulate(struct ttm_tt *ttm)
144 : {
145 0 : ttm_pool_unpopulate(ttm);
146 0 : }
147 : EXPORT_SYMBOL(ttm_agp_tt_unpopulate);
148 :
149 : #endif
|