]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/tga/tga_pci.c
This commit was generated by cvs2svn to compensate for changes in r157016,
[FreeBSD/FreeBSD.git] / sys / dev / tga / tga_pci.c
1 /*-
2  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
3  * All rights reserved.
4  *
5  * Author: Chris G. Demetriou
6  * 
7  * Permission to use, copy, modify and distribute this software and
8  * its documentation is hereby granted, provided that both the copyright
9  * notice and this permission notice appear in all copies of the
10  * software, derivative works or modified versions, and any portions
11  * thereof, and that both notices appear in supporting documentation.
12  * 
13  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
14  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
15  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16  * 
17  * Carnegie Mellon requests users of this software to return to
18  *
19  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
20  *  School of Computer Science
21  *  Carnegie Mellon University
22  *  Pittsburgh PA 15213-3890
23  *
24  * any improvements or extensions that they make and grant Carnegie the
25  * rights to redistribute these changes.
26  *
27  * Copyright (c) 2000 Andrew Miklic, Andrew Gallatin, and Thomas V. Crimi
28  */
29
30 #include "opt_fb.h"
31
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/conf.h>
40 #include <sys/proc.h>
41 #include <sys/fcntl.h>
42 #include <sys/malloc.h>
43 #include <sys/fbio.h>
44
45 #include <vm/vm.h>
46 #include <vm/vm_param.h>
47 #include <vm/pmap.h>
48
49 #include <machine/md_var.h>
50 #include <machine/pc/bios.h>
51 #include <machine/clock.h>
52 #include <machine/bus.h>
53 #include <machine/pc/vesa.h>
54 #include <machine/resource.h>
55
56 #include <sys/bus.h>
57 #include <sys/rman.h>
58
59 #include <dev/pci/pcireg.h>
60 #include <dev/pci/pcivar.h>
61
62 #include <dev/fb/fbreg.h>
63 #include <dev/fb/tga.h>
64 #include <dev/tga/tga_pci.h>
65 #include <dev/fb/gfb.h>
66 #include <dev/gfb/gfb_pci.h>
67
68 static int tga_probe(device_t);
69 static int tga_attach(device_t);
70 static void tga_intr(void *);
71
72 static device_method_t tga_methods[] = {
73         DEVMETHOD(device_probe, tga_probe),
74         DEVMETHOD(device_attach, tga_attach),
75         DEVMETHOD(device_detach, pcigfb_detach),
76         { 0, 0 }
77 };
78
79 static driver_t tga_driver = {
80         "tga",
81         tga_methods,
82         sizeof(struct gfb_softc)
83 };
84
85 static devclass_t tga_devclass;
86
87 DRIVER_MODULE(tga, pci, tga_driver, tga_devclass, 0, 0);
88
89 static struct gfb_type tga_devs[] = {
90         { DEC_VENDORID, DEC_DEVICEID_TGA,
91         "DEC TGA (21030) 2D Graphics Accelerator" },
92         { 0, 0, NULL }
93 };
94
95 #ifdef FB_INSTALL_CDEV
96
97 static struct cdevsw tga_cdevsw = {
98         .d_version =    D_VERSION,
99         .d_flags =      D_NEEDGIANT,
100         .d_open =       pcigfb_open,
101         .d_close =      pcigfb_close,
102         .d_read =       pcigfb_read,
103         .d_write =      pcigfb_write,
104         .d_ioctl =      pcigfb_ioctl,
105         .d_mmap =       pcigfb_mmap,
106         .d_name =       "tga",
107 };
108
109 #endif /* FB_INSTALL_CDEV */
110
111 static int
112 tga_probe(device_t dev)
113 {
114         int error;
115         gfb_type_t t;
116
117         t = tga_devs;
118         error = ENXIO;
119         while(t->name != NULL) {
120                 if((pci_get_vendor(dev) == t->vendor_id) &&
121                    (pci_get_device(dev) == t->device_id)) {
122                         device_set_desc(dev, t->name);
123                         error = BUS_PROBE_DEFAULT;
124                         break;
125                 }
126                 t++;
127         }
128         return(error);
129 }
130
131 static int
132 tga_attach(device_t dev)
133 {
134         gfb_softc_t sc;
135         int unit, error, rid;
136
137         error = 0;
138         unit = device_get_unit(dev);
139         sc = device_get_softc(dev);
140         sc->driver_name = TGA_DRIVER_NAME;
141         switch(pci_get_device(dev)) {
142         case DEC_DEVICEID_TGA2:
143                 sc->model = 1;
144                 sc->type = KD_TGA2;
145                 break;
146         case DEC_DEVICEID_TGA:
147                 sc->model = 0;
148                 sc->type = KD_TGA;
149                 break;
150         default:
151                 device_printf(dev, "Unrecognized TGA type\n");
152                 goto fail;
153         }
154         if((error = pcigfb_attach(dev))) {
155                 goto fail;
156         }
157         sc->regs = sc->bhandle + TGA_MEM_CREGS;
158         error = bus_setup_intr(dev, sc->irq, INTR_TYPE_TTY, tga_intr, sc,
159                     &sc->intrhand);
160         if(error) {
161                 device_printf(dev, "couldn't set up irq\n");
162                 goto fail;
163         }
164         switch(sc->rev) {
165         case 0x1:
166         case 0x2:
167         case 0x3:
168                 device_printf(dev, "TGA (21030) step %c\n", 'A' + sc->rev - 1);
169                 break;
170
171         case 0x20:
172                 device_printf(dev, "TGA2 (21130) abstract software model\n");
173                 break;
174
175         case 0x21:
176         case 0x22:
177                 device_printf(dev, "TGA2 (21130) pass %d\n", sc->rev - 0x20);
178                 break;
179
180         default:
181                 device_printf(dev, "Unknown stepping (0x%x)\n", sc->rev);
182                 break;
183         }
184 #ifdef FB_INSTALL_CDEV
185         sc->cdevsw = &tga_cdevsw;
186         sc->devt = make_dev(sc->cdevsw, unit, UID_ROOT, GID_WHEEL, 0600,
187             "tga%x", unit);
188 #endif /* FB_INSTALL_CDEV */
189         goto done;
190 fail:
191         if(sc->intrhand != NULL) {
192                 bus_teardown_intr(dev, sc->irq, sc->intrhand);
193                 sc->intrhand = NULL;
194         }
195         if(sc->irq != NULL) {
196                 rid = 0x0;
197                 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->irq);
198                 sc->irq = NULL;
199         }
200         if(sc->res != NULL) {
201                 rid = GFB_MEM_BASE_RID;
202                 bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->res);
203                 sc->res = NULL;
204         }
205         error = ENXIO;
206 done:
207         return(error);
208 }
209
210 static void 
211 tga_intr(void *v)
212 {
213         struct gfb_softc *sc = (struct gfb_softc *)v;
214         u_int32_t reg;
215
216         reg = READ_GFB_REGISTER(sc->adp, TGA_REG_SISR);
217         if((reg & 0x00010001) != 0x00010001) {
218
219                 /* Odd. We never set any of the other interrupt enables. */
220                 if((reg & 0x1f) != 0) {
221
222                         /* Clear the mysterious pending interrupts. */
223                         WRITE_GFB_REGISTER(sc->adp, TGA_REG_SISR, (reg & 0x1f));
224                         GFB_REGISTER_WRITE_BARRIER(sc, TGA_REG_SISR, 1);
225
226                         /* This was our interrupt, even if we're puzzled as to
227                          * why we got it.  Don't make the interrupt handler
228                          * think it was a stray.
229                          */
230                 }
231         }
232
233         /* Call the scheduled handler... */
234         sc->gfbc->ramdac_intr(sc);
235
236         /*
237            Clear interrupt field (this way, we will force a
238            memory error if we get an unexpected interrupt)...
239         */
240         sc->gfbc->ramdac_intr = NULL;
241
242         /* Disable the interrupt... */
243         WRITE_GFB_REGISTER(sc->adp, TGA_REG_SISR, 0x00000001);
244         GFB_REGISTER_WRITE_BARRIER(sc, TGA_REG_SISR, 1);
245 }