igsfb_pci.c revision 1.2.8.3 1 1.2.8.3 jdolecek /* $NetBSD: igsfb_pci.c,v 1.2.8.3 2002/09/06 08:45:22 jdolecek Exp $ */
2 1.2.8.2 jdolecek
3 1.2.8.2 jdolecek /*
4 1.2.8.2 jdolecek * Copyright (c) 2002 Valeriy E. Ushakov
5 1.2.8.2 jdolecek * All rights reserved.
6 1.2.8.2 jdolecek *
7 1.2.8.2 jdolecek * Redistribution and use in source and binary forms, with or without
8 1.2.8.2 jdolecek * modification, are permitted provided that the following conditions
9 1.2.8.2 jdolecek * are met:
10 1.2.8.2 jdolecek * 1. Redistributions of source code must retain the above copyright
11 1.2.8.2 jdolecek * notice, this list of conditions and the following disclaimer.
12 1.2.8.2 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.8.2 jdolecek * notice, this list of conditions and the following disclaimer in the
14 1.2.8.2 jdolecek * documentation and/or other materials provided with the distribution.
15 1.2.8.2 jdolecek * 3. The name of the author may not be used to endorse or promote products
16 1.2.8.2 jdolecek * derived from this software without specific prior written permission
17 1.2.8.2 jdolecek *
18 1.2.8.2 jdolecek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.2.8.2 jdolecek * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.2.8.2 jdolecek * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.2.8.2 jdolecek * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.2.8.2 jdolecek * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.2.8.2 jdolecek * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.2.8.2 jdolecek * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.2.8.2 jdolecek * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.2.8.2 jdolecek * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.2.8.2 jdolecek * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.2.8.2 jdolecek */
29 1.2.8.2 jdolecek
30 1.2.8.2 jdolecek /*
31 1.2.8.3 jdolecek * Integraphics Systems IGA 168x and CyberPro series.
32 1.2.8.3 jdolecek * Only tested on IGA 1682 in Krups JavaStation-NC.
33 1.2.8.2 jdolecek */
34 1.2.8.2 jdolecek #include <sys/cdefs.h>
35 1.2.8.3 jdolecek __KERNEL_RCSID(0, "$NetBSD: igsfb_pci.c,v 1.2.8.3 2002/09/06 08:45:22 jdolecek Exp $");
36 1.2.8.2 jdolecek
37 1.2.8.2 jdolecek #include <sys/param.h>
38 1.2.8.2 jdolecek #include <sys/systm.h>
39 1.2.8.2 jdolecek #include <sys/kernel.h>
40 1.2.8.2 jdolecek #include <sys/device.h>
41 1.2.8.2 jdolecek #include <sys/malloc.h>
42 1.2.8.2 jdolecek #include <sys/buf.h>
43 1.2.8.2 jdolecek
44 1.2.8.2 jdolecek #include <machine/autoconf.h>
45 1.2.8.2 jdolecek #include <machine/bus.h>
46 1.2.8.2 jdolecek #include <machine/intr.h>
47 1.2.8.2 jdolecek
48 1.2.8.2 jdolecek #include <dev/pci/pcivar.h>
49 1.2.8.2 jdolecek #include <dev/pci/pcireg.h>
50 1.2.8.2 jdolecek #include <dev/pci/pcidevs.h>
51 1.2.8.2 jdolecek
52 1.2.8.2 jdolecek #include <dev/wscons/wsconsio.h>
53 1.2.8.2 jdolecek #include <dev/ic/igsfbreg.h>
54 1.2.8.2 jdolecek #include <dev/ic/igsfbvar.h>
55 1.2.8.2 jdolecek
56 1.2.8.2 jdolecek
57 1.2.8.2 jdolecek static int igsfb_pci_match(struct device *, struct cfdata *, void *);
58 1.2.8.2 jdolecek static void igsfb_pci_attach(struct device *, struct device *, void *);
59 1.2.8.2 jdolecek
60 1.2.8.2 jdolecek const struct cfattach igsfb_pci_ca = {
61 1.2.8.2 jdolecek sizeof(struct igsfb_softc), igsfb_pci_match, igsfb_pci_attach,
62 1.2.8.2 jdolecek };
63 1.2.8.2 jdolecek
64 1.2.8.2 jdolecek
65 1.2.8.2 jdolecek static int
66 1.2.8.2 jdolecek igsfb_pci_match(parent, match, aux)
67 1.2.8.2 jdolecek struct device *parent;
68 1.2.8.2 jdolecek struct cfdata *match;
69 1.2.8.2 jdolecek void *aux;
70 1.2.8.2 jdolecek {
71 1.2.8.2 jdolecek struct pci_attach_args *pa = aux;
72 1.2.8.2 jdolecek
73 1.2.8.2 jdolecek if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEGRAPHICS)
74 1.2.8.2 jdolecek return (0);
75 1.2.8.2 jdolecek
76 1.2.8.2 jdolecek /* probably can drive iga1680 and cyberpro cards as well */
77 1.2.8.2 jdolecek if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682)
78 1.2.8.2 jdolecek return (1);
79 1.2.8.2 jdolecek
80 1.2.8.2 jdolecek return (0);
81 1.2.8.2 jdolecek }
82 1.2.8.2 jdolecek
83 1.2.8.2 jdolecek
84 1.2.8.2 jdolecek /*
85 1.2.8.2 jdolecek * Note, that the chip may still be not enabled (e.g. JavaStation PROM
86 1.2.8.2 jdolecek * doesn't bother to init the chip if PROM output goes to serial).
87 1.2.8.2 jdolecek */
88 1.2.8.2 jdolecek static void
89 1.2.8.2 jdolecek igsfb_pci_attach(parent, self, aux)
90 1.2.8.2 jdolecek struct device *parent, *self;
91 1.2.8.2 jdolecek void *aux;
92 1.2.8.2 jdolecek {
93 1.2.8.2 jdolecek struct igsfb_softc *sc = (struct igsfb_softc *)self;
94 1.2.8.2 jdolecek struct pci_attach_args *pa = aux;
95 1.2.8.2 jdolecek bus_addr_t iobase;
96 1.2.8.2 jdolecek int ioflags;
97 1.2.8.2 jdolecek int isconsole;
98 1.2.8.2 jdolecek char devinfo[256];
99 1.2.8.2 jdolecek
100 1.2.8.2 jdolecek pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
101 1.2.8.2 jdolecek printf(": %s, revision 0x%02x\n", devinfo, PCI_REVISION(pa->pa_class));
102 1.2.8.2 jdolecek
103 1.2.8.2 jdolecek if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682)
104 1.2.8.2 jdolecek sc->sc_is2k = 0;
105 1.2.8.2 jdolecek else
106 1.2.8.2 jdolecek sc->sc_is2k = 1;
107 1.2.8.2 jdolecek
108 1.2.8.2 jdolecek /*
109 1.2.8.3 jdolecek * Enable the chip. This always goes through i/o space
110 1.2.8.3 jdolecek * because that's the only way that is guaranteed to enable
111 1.2.8.3 jdolecek * completely uninitialized card.
112 1.2.8.2 jdolecek */
113 1.2.8.3 jdolecek if (igsfb_enable(pa->pa_iot) != 0)
114 1.2.8.3 jdolecek return;
115 1.2.8.2 jdolecek
116 1.2.8.2 jdolecek /*
117 1.2.8.3 jdolecek * Configure memory space first since for CyberPro we use
118 1.2.8.3 jdolecek * memory-mapped i/o access. Note that we are NOT mapping any
119 1.2.8.3 jdolecek * of it yet. (XXX: search for memory BAR)
120 1.2.8.2 jdolecek */
121 1.2.8.2 jdolecek #define IGS_MEM_MAPREG (PCI_MAPREG_START + 0)
122 1.2.8.2 jdolecek
123 1.2.8.2 jdolecek sc->sc_memt = pa->pa_memt;
124 1.2.8.2 jdolecek if (pci_mapreg_info(pa->pa_pc, pa->pa_tag,
125 1.2.8.2 jdolecek IGS_MEM_MAPREG, PCI_MAPREG_TYPE_MEM,
126 1.2.8.2 jdolecek &sc->sc_memaddr, &sc->sc_memsz, &sc->sc_memflags) != 0)
127 1.2.8.2 jdolecek {
128 1.2.8.2 jdolecek printf("unable to configure memory space\n");
129 1.2.8.2 jdolecek return;
130 1.2.8.2 jdolecek }
131 1.2.8.2 jdolecek
132 1.2.8.2 jdolecek /*
133 1.2.8.3 jdolecek * Configure I/O space. On CyberPro use MMIO. IGS 168x
134 1.2.8.3 jdolecek * doesn't have a BAR for its i/o, so we have to hardcode it.
135 1.2.8.2 jdolecek */
136 1.2.8.3 jdolecek if (sc->sc_is2k) {
137 1.2.8.2 jdolecek sc->sc_iot = sc->sc_memt;
138 1.2.8.3 jdolecek iobase = IGS_MEM_MMIO_SELECT | sc->sc_memaddr;
139 1.2.8.2 jdolecek ioflags = sc->sc_memflags;
140 1.2.8.2 jdolecek } else {
141 1.2.8.3 jdolecek /* feh, 1682 config denies having io space registers */
142 1.2.8.2 jdolecek sc->sc_iot = pa->pa_iot;
143 1.2.8.2 jdolecek iobase = 0;
144 1.2.8.2 jdolecek ioflags = 0;
145 1.2.8.2 jdolecek }
146 1.2.8.2 jdolecek
147 1.2.8.3 jdolecek /*
148 1.2.8.3 jdolecek * Map I/O registers. This is done in bus glue, not in common
149 1.2.8.3 jdolecek * code because on e.g. ISA bus we'd need to access registers
150 1.2.8.3 jdolecek * to obtain/program linear memory location.
151 1.2.8.3 jdolecek */
152 1.2.8.3 jdolecek if (bus_space_map(sc->sc_iot,
153 1.2.8.3 jdolecek iobase + IGS_REG_BASE, IGS_REG_SIZE, ioflags,
154 1.2.8.2 jdolecek &sc->sc_ioh) != 0)
155 1.2.8.2 jdolecek {
156 1.2.8.3 jdolecek printf("unable to map I/O registers\n");
157 1.2.8.2 jdolecek return;
158 1.2.8.2 jdolecek }
159 1.2.8.2 jdolecek
160 1.2.8.3 jdolecek /* TODO: Map CRTC??? This simple driver doesn't use it so far. */
161 1.2.8.2 jdolecek
162 1.2.8.3 jdolecek /*
163 1.2.8.3 jdolecek * TODO: Map graphic coprocessor registers. not sure if this
164 1.2.8.3 jdolecek * needs to be done in bus glue or can be moved to common
165 1.2.8.3 jdolecek * attach code.
166 1.2.8.3 jdolecek */
167 1.2.8.2 jdolecek
168 1.2.8.3 jdolecek isconsole = 0;
169 1.2.8.3 jdolecek #ifdef __sparc__ /* XXX: this doesn't belong here */
170 1.2.8.2 jdolecek if (PCITAG_NODE(pa->pa_tag) == prom_instance_to_package(prom_stdout()))
171 1.2.8.2 jdolecek isconsole = 1;
172 1.2.8.3 jdolecek #endif
173 1.2.8.2 jdolecek
174 1.2.8.2 jdolecek igsfb_common_attach(sc, isconsole);
175 1.2.8.2 jdolecek }
176