puccn.c revision 1.1.2.3 1 1.1.2.3 bouyer /* $NetBSD: puccn.c,v 1.1.2.3 2000/12/13 15:50:10 bouyer Exp $ */
2 1.1.2.2 bouyer
3 1.1.2.2 bouyer /*
4 1.1.2.2 bouyer * Derived from pci.c
5 1.1.2.2 bouyer * Copyright (c) 2000 Geocast Networks Systems. All rights reserved.
6 1.1.2.2 bouyer *
7 1.1.2.2 bouyer * Copyright (c) 1995, 1996, 1997, 1998
8 1.1.2.2 bouyer * Christopher G. Demetriou. All rights reserved.
9 1.1.2.2 bouyer * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
10 1.1.2.2 bouyer *
11 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.2.2 bouyer * are met:
14 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
16 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
17 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
18 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
19 1.1.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
20 1.1.2.2 bouyer * must display the following acknowledgement:
21 1.1.2.2 bouyer * This product includes software developed by Charles M. Hannum.
22 1.1.2.2 bouyer * 4. The name of the author may not be used to endorse or promote products
23 1.1.2.2 bouyer * derived from this software without specific prior written permission.
24 1.1.2.2 bouyer *
25 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 1.1.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 1.1.2.2 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 1.1.2.2 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 1.1.2.2 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 1.1.2.2 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 1.1.2.2 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 1.1.2.2 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 1.1.2.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 1.1.2.2 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 1.1.2.2 bouyer */
36 1.1.2.2 bouyer
37 1.1.2.2 bouyer
38 1.1.2.2 bouyer /*
39 1.1.2.2 bouyer * Machine independent support for PCI serial console support.
40 1.1.2.2 bouyer *
41 1.1.2.2 bouyer * Scan the PCI bus for something which resembles a 16550
42 1.1.2.2 bouyer */
43 1.1.2.2 bouyer
44 1.1.2.2 bouyer #include <sys/param.h>
45 1.1.2.2 bouyer #include <sys/systm.h>
46 1.1.2.2 bouyer #include <sys/conf.h>
47 1.1.2.2 bouyer #include <sys/device.h>
48 1.1.2.2 bouyer
49 1.1.2.2 bouyer #include <dev/pci/pcireg.h>
50 1.1.2.2 bouyer #include <dev/pci/pcivar.h>
51 1.1.2.2 bouyer #include <dev/pci/pcidevs.h>
52 1.1.2.2 bouyer
53 1.1.2.2 bouyer #include <sys/termios.h>
54 1.1.2.2 bouyer #include <dev/ic/comreg.h>
55 1.1.2.2 bouyer #include <dev/ic/comvar.h>
56 1.1.2.2 bouyer
57 1.1.2.2 bouyer #include <dev/cons.h>
58 1.1.2.2 bouyer
59 1.1.2.2 bouyer #include <dev/pci/pucvar.h>
60 1.1.2.2 bouyer #include <dev/pci/puccn.h>
61 1.1.2.2 bouyer
62 1.1.2.2 bouyer #ifndef CONSPEED
63 1.1.2.2 bouyer #define CONSPEED TTYDEF_SPEED
64 1.1.2.2 bouyer #endif
65 1.1.2.2 bouyer #ifndef CONMODE
66 1.1.2.2 bouyer #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE|CSTOPB|PARENB))|CS8) /* 8N1 */
67 1.1.2.2 bouyer #endif
68 1.1.2.2 bouyer
69 1.1.2.2 bouyer #ifdef i386 /* Handle i386 directly */
70 1.1.2.2 bouyer int
71 1.1.2.2 bouyer cpu_comcnprobe(struct consdev *cn, struct pci_attach_args *pa)
72 1.1.2.2 bouyer {
73 1.1.2.2 bouyer pci_mode_detect();
74 1.1.2.2 bouyer pa->pa_iot = I386_BUS_SPACE_IO;
75 1.1.2.2 bouyer pa->pa_pc = 0;
76 1.1.2.2 bouyer pa->pa_tag = pci_make_tag(0, 0, 31, 0);
77 1.1.2.2 bouyer return 0;
78 1.1.2.2 bouyer }
79 1.1.2.2 bouyer #endif
80 1.1.2.2 bouyer
81 1.1.2.2 bouyer cons_decl(com);
82 1.1.2.2 bouyer
83 1.1.2.2 bouyer static bus_addr_t puccnbase;
84 1.1.2.2 bouyer static bus_space_tag_t puctag;
85 1.1.2.2 bouyer
86 1.1.2.2 bouyer #ifdef KGDB
87 1.1.2.2 bouyer static bus_addr_t pucgdbbase;
88 1.1.2.2 bouyer #endif
89 1.1.2.2 bouyer
90 1.1.2.2 bouyer /*
91 1.1.2.2 bouyer * Static dev/func variables allow pucprobe to be called multiple times,
92 1.1.2.2 bouyer * resuming the search where it left off, never retrying the same adaptor.
93 1.1.2.2 bouyer */
94 1.1.2.2 bouyer
95 1.1.2.2 bouyer static bus_addr_t
96 1.1.2.2 bouyer pucprobe_doit(struct consdev *cn)
97 1.1.2.2 bouyer {
98 1.1.2.2 bouyer struct pci_attach_args pa;
99 1.1.2.2 bouyer int bus;
100 1.1.2.2 bouyer static int dev = 0, func = 0;
101 1.1.2.2 bouyer int maxdev, nfunctions, i;
102 1.1.2.2 bouyer pcireg_t reg, bhlcr, subsys;
103 1.1.2.2 bouyer int foundport = 0;
104 1.1.2.2 bouyer const struct puc_device_description *desc;
105 1.1.2.2 bouyer pcireg_t base;
106 1.1.2.2 bouyer
107 1.1.2.2 bouyer /* Fetch our tags */
108 1.1.2.2 bouyer if (cpu_comcnprobe(cn, &pa) != 0) {
109 1.1.2.2 bouyer return 0;
110 1.1.2.2 bouyer }
111 1.1.2.2 bouyer puctag = pa.pa_iot;
112 1.1.2.2 bouyer pci_decompose_tag(pa.pa_pc, pa.pa_tag, &bus, &maxdev, NULL);
113 1.1.2.2 bouyer
114 1.1.2.2 bouyer /* scan through devices */
115 1.1.2.2 bouyer
116 1.1.2.2 bouyer for (; dev <= maxdev ; dev++) {
117 1.1.2.2 bouyer pa.pa_tag = pci_make_tag(pa.pa_pc, bus, dev, 0);
118 1.1.2.2 bouyer reg = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_ID_REG);
119 1.1.2.2 bouyer if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID
120 1.1.2.2 bouyer || PCI_VENDOR(reg) == 0)
121 1.1.2.2 bouyer continue;
122 1.1.2.2 bouyer bhlcr = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_BHLC_REG);
123 1.1.2.2 bouyer if (PCI_HDRTYPE_MULTIFN(bhlcr)) {
124 1.1.2.2 bouyer nfunctions = 8;
125 1.1.2.2 bouyer } else {
126 1.1.2.2 bouyer nfunctions = 1;
127 1.1.2.2 bouyer }
128 1.1.2.2 bouyer resume_scan:
129 1.1.2.2 bouyer for (; func < nfunctions; func++) {
130 1.1.2.2 bouyer pa.pa_tag = pci_make_tag(pa.pa_pc, bus, dev, func);
131 1.1.2.2 bouyer reg = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_CLASS_REG);
132 1.1.2.2 bouyer if (PCI_CLASS(reg) == PCI_CLASS_COMMUNICATIONS
133 1.1.2.2 bouyer && PCI_SUBCLASS(reg)
134 1.1.2.2 bouyer == PCI_SUBCLASS_COMMUNICATIONS_SERIAL) {
135 1.1.2.2 bouyer pa.pa_id = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_ID_REG);
136 1.1.2.2 bouyer subsys = pci_conf_read(pa.pa_pc, pa.pa_tag,
137 1.1.2.2 bouyer PCI_SUBSYS_ID_REG);
138 1.1.2.2 bouyer foundport = 1;
139 1.1.2.2 bouyer break;
140 1.1.2.2 bouyer }
141 1.1.2.2 bouyer }
142 1.1.2.2 bouyer if (foundport)
143 1.1.2.2 bouyer break;
144 1.1.2.2 bouyer
145 1.1.2.2 bouyer func = 0;
146 1.1.2.2 bouyer }
147 1.1.2.2 bouyer if (!foundport)
148 1.1.2.2 bouyer return 0;
149 1.1.2.2 bouyer foundport = 0;
150 1.1.2.2 bouyer
151 1.1.2.2 bouyer desc = puc_find_description(PCI_VENDOR(pa.pa_id),
152 1.1.2.2 bouyer PCI_PRODUCT(pa.pa_id), PCI_VENDOR(subsys), PCI_PRODUCT(subsys));
153 1.1.2.2 bouyer if (desc == NULL) {
154 1.1.2.2 bouyer func++;
155 1.1.2.2 bouyer goto resume_scan;
156 1.1.2.2 bouyer }
157 1.1.2.2 bouyer
158 1.1.2.2 bouyer for (i = 0; PUC_PORT_VALID(desc, i); i++)
159 1.1.2.2 bouyer {
160 1.1.2.2 bouyer if (desc->ports[i].type != PUC_PORT_TYPE_COM)
161 1.1.2.2 bouyer continue;
162 1.1.2.2 bouyer base = pci_conf_read(pa.pa_pc, pa.pa_tag, desc->ports[i].bar);
163 1.1.2.2 bouyer base += desc->ports[i].offset;
164 1.1.2.2 bouyer
165 1.1.2.2 bouyer if (PCI_MAPREG_TYPE(base) != PCI_MAPREG_TYPE_IO)
166 1.1.2.2 bouyer continue;
167 1.1.2.2 bouyer base = PCI_MAPREG_IO_ADDR(base);
168 1.1.2.2 bouyer if (com_is_console(puctag, base, NULL))
169 1.1.2.2 bouyer continue;
170 1.1.2.2 bouyer foundport = 1;
171 1.1.2.2 bouyer break;
172 1.1.2.2 bouyer }
173 1.1.2.2 bouyer
174 1.1.2.2 bouyer if (foundport == 0) {
175 1.1.2.2 bouyer func++;
176 1.1.2.2 bouyer goto resume_scan;
177 1.1.2.2 bouyer }
178 1.1.2.2 bouyer
179 1.1.2.2 bouyer cn->cn_pri = CN_REMOTE;
180 1.1.2.2 bouyer return PCI_MAPREG_IO_ADDR(base);
181 1.1.2.2 bouyer }
182 1.1.2.2 bouyer
183 1.1.2.2 bouyer #ifdef KGDB
184 1.1.2.2 bouyer void comgdbprobe(struct consdev *);
185 1.1.2.2 bouyer void comgdbinit(struct consdev *);
186 1.1.2.2 bouyer
187 1.1.2.2 bouyer void
188 1.1.2.2 bouyer comgdbprobe(struct consdev *cn)
189 1.1.2.2 bouyer {
190 1.1.2.2 bouyer pucgdbbase = pucprobe_doit(cn);
191 1.1.2.2 bouyer }
192 1.1.2.2 bouyer
193 1.1.2.2 bouyer void
194 1.1.2.2 bouyer comgdbinit(struct consdev *cn)
195 1.1.2.2 bouyer {
196 1.1.2.2 bouyer if (pucgdbbase == 0) {
197 1.1.2.2 bouyer return;
198 1.1.2.2 bouyer }
199 1.1.2.2 bouyer com_kgdb_attach(puctag, pucgdbbase, CONSPEED, COM_FREQ, CONMODE);
200 1.1.2.2 bouyer }
201 1.1.2.2 bouyer #endif
202 1.1.2.2 bouyer
203 1.1.2.2 bouyer void
204 1.1.2.2 bouyer comcnprobe(struct consdev *cn)
205 1.1.2.2 bouyer {
206 1.1.2.2 bouyer puccnbase = pucprobe_doit(cn);
207 1.1.2.2 bouyer }
208 1.1.2.2 bouyer
209 1.1.2.2 bouyer void
210 1.1.2.2 bouyer comcninit(struct consdev *cn)
211 1.1.2.2 bouyer {
212 1.1.2.2 bouyer if (puccnbase == 0) {
213 1.1.2.2 bouyer return;
214 1.1.2.2 bouyer }
215 1.1.2.2 bouyer comcnattach(puctag, puccnbase, CONSPEED, COM_FREQ, CONMODE);
216 1.1.2.2 bouyer }
217 1.1.2.2 bouyer
218 1.1.2.2 bouyer /* comcngetc, comcnputc, comcnpollc provided by dev/ic/com.c */
219