Deleted Added
sdiff udiff text old ( 144809 ) new ( 150645 )
full compact
1/*-
2 * Copyright (c) 2004 Jung-uk Kim
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 9 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/agp/agp_amd64.c 144809 2005-04-08 18:04:39Z obrien $");
29
30#include "opt_bus.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/malloc.h>
35#include <sys/kernel.h>
36#include <sys/module.h>

--- 13 unchanged lines hidden (view full) ---

50#include <machine/bus.h>
51#include <machine/resource.h>
52#include <sys/rman.h>
53
54/* XXX */
55extern void pci_cfgregwrite(int, int, int, int, uint32_t, int);
56extern uint32_t pci_cfgregread(int, int, int, int, int);
57
58MALLOC_DECLARE(M_AGP);
59
60#define AMD64_MAX_MCTRL 8
61
62struct agp_amd64_softc {
63 struct agp_softc agp;
64 uint32_t initial_aperture; /* aperture size at startup */
65 struct agp_gatt *gatt;
66 int mctrl[AMD64_MAX_MCTRL];
67 int n_mctrl;
68};
69
70static const char*
71agp_amd64_match(device_t dev)
72{
73 if (pci_get_class(dev) != PCIC_BRIDGE
74 || pci_get_subclass(dev) != PCIS_BRIDGE_HOST)
75 return NULL;
76
77 if (agp_find_caps(dev) == 0)
78 return NULL;
79
80 switch (pci_get_devid(dev)) {
81 case 0x74541022:
82 return ("AMD 8151 AGP graphics tunnel");
83 case 0x07551039:
84 return ("SiS 755 host to AGP bridge");
85 case 0x00d110de:
86 return ("NVIDIA nForce3 AGP Controller");
87 case 0x00e110de:
88 return ("NVIDIA nForce3-250 AGP Controller");
89 case 0x02041106:
90 return ("VIA 8380 host to PCI bridge");
91 case 0x02821106:
92 return ("VIA K8T800Pro host to PCI bridge");
93 case 0x31881106:
94 return ("VIA 8385 host to PCI bridge");
95 };
96
97 return NULL;
98}
99
100static int
101agp_amd64_probe(device_t dev)
102{
103 const char *desc;
104
105 if (resource_disabled("agp", device_get_unit(dev)))
106 return ENXIO;
107 if ((desc = agp_amd64_match(dev))) {
108 device_verbose(dev);

--- 17 unchanged lines hidden (view full) ---

126 n++;
127 }
128
129 if (n == 0)
130 return ENXIO;
131
132 sc->n_mctrl = n;
133
134 if (bootverbose)
135 printf("AMD64: %d Misc. Control unit(s) found.\n", sc->n_mctrl);
136
137 if ((error = agp_generic_attach(dev)))
138 return error;
139
140 sc->initial_aperture = AGP_GET_APERTURE(dev);
141
142 for (;;) {
143 gatt = agp_alloc_gatt(dev);
144 if (gatt)
145 break;
146
147 /*
148 * Probably contigmalloc failure. Try reducing the
149 * aperture so that the gatt size reduces.

--- 75 unchanged lines hidden (view full) ---

225{
226 struct agp_amd64_softc *sc = device_get_softc(dev);
227 uint32_t i;
228 int j;
229
230 for (i = 0; i < AGP_AMD64_TABLE_SIZE; i++)
231 if (agp_amd64_table[i] == aperture)
232 break;
233 if (i == AGP_AMD64_TABLE_SIZE)
234 return EINVAL;
235
236 for (j = 0; j < sc->n_mctrl; j++)
237 pci_cfgregwrite(0, sc->mctrl[j], 3, AGP_AMD64_APCTRL,
238 (pci_cfgregread(0, sc->mctrl[j], 3, AGP_AMD64_APCTRL, 4) &
239 ~(AGP_AMD64_APCTRL_SIZE_MASK)) | (i << 1), 4);
240
241 return 0;
242}
243
244static int
245agp_amd64_bind_page(device_t dev, int offset, vm_offset_t physical)
246{
247 struct agp_amd64_softc *sc = device_get_softc(dev);
248

--- 23 unchanged lines hidden (view full) ---

272 int i;
273
274 for (i = 0; i < sc->n_mctrl; i++)
275 pci_cfgregwrite(0, sc->mctrl[i], 3, AGP_AMD64_CACHECTRL,
276 pci_cfgregread(0, sc->mctrl[i], 3, AGP_AMD64_CACHECTRL, 4) |
277 AGP_AMD64_CACHECTRL_INVGART, 4);
278}
279
280static device_method_t agp_amd64_methods[] = {
281 /* Device interface */
282 DEVMETHOD(device_probe, agp_amd64_probe),
283 DEVMETHOD(device_attach, agp_amd64_attach),
284 DEVMETHOD(device_detach, agp_amd64_detach),
285 DEVMETHOD(device_shutdown, bus_generic_shutdown),
286 DEVMETHOD(device_suspend, bus_generic_suspend),
287 DEVMETHOD(device_resume, bus_generic_resume),

--- 27 unchanged lines hidden ---