Annotation of sys/arch/mvme88k/dev/pcctwo.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: pcctwo.c,v 1.29 2006/05/08 14:36:10 miod Exp $ */
2: /*
3: * Copyright (c) 1995 Theo de Raadt
4: * All rights reserved.
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: * 1. Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: * 2. Redistributions in binary form must reproduce the above copyright
12: * notice, this list of conditions and the following disclaimer in the
13: * documentation and/or other materials provided with the distribution.
14: *
15: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25: */
26:
27: /*
28: * VME1x7 PCC2 chip
29: */
30: #include <sys/param.h>
31: #include <sys/conf.h>
32: #include <sys/ioctl.h>
33: #include <sys/proc.h>
34: #include <sys/user.h>
35: #include <sys/tty.h>
36: #include <sys/uio.h>
37: #include <sys/systm.h>
38: #include <sys/kernel.h>
39: #include <sys/syslog.h>
40: #include <sys/fcntl.h>
41: #include <sys/device.h>
42:
43: #include <machine/autoconf.h>
44: #include <machine/cpu.h>
45:
46: #include <dev/cons.h>
47:
48: #include <mvme88k/dev/pcctworeg.h>
49: #include <mvme88k/dev/pcctwovar.h>
50:
51: #include "bussw.h"
52:
53: void pcctwoattach(struct device *, struct device *, void *);
54: int pcctwomatch(struct device *, void *, void *);
55:
56: struct cfattach pcctwo_ca = {
57: sizeof(struct pcctwosoftc), pcctwomatch, pcctwoattach
58: };
59:
60: struct cfdriver pcctwo_cd = {
61: NULL, "pcctwo", DV_DULL
62: };
63:
64: int pcctwo_print(void *args, const char *bus);
65: int pcctwo_scan(struct device *parent, void *child, void *args);
66:
67: int
68: pcctwomatch(parent, vcf, args)
69: struct device *parent;
70: void *vcf, *args;
71: {
72: struct confargs *ca = args;
73: bus_space_handle_t ioh;
74: int rc;
75: u_int8_t chipid;
76:
77: /* Bomb if wrong cpu */
78: switch (brdtyp) {
79: case BRD_187:
80: case BRD_8120:
81: case BRD_197:
82: break;
83: default:
84: return 0;
85: }
86:
87: if (bus_space_map(ca->ca_iot, PCC2_BASE, PCC2_SIZE,
88: 0, &ioh) != 0)
89: return 0;
90: rc = badaddr((vaddr_t)bus_space_vaddr(ca->ca_iot, ioh), 4);
91: if (rc == 0) {
92: chipid = bus_space_read_1(ca->ca_iot, ioh, PCCTWO_CHIPID);
93: if (chipid != PCC2_ID) {
94: #ifdef DEBUG
95: printf("==> pcctwo: wrong chip id %x.\n", chipid);
96: rc = -1;
97: #endif
98: }
99: }
100: bus_space_unmap(ca->ca_iot, ioh, PCC2_SIZE);
101:
102: return rc == 0;
103: }
104:
105: void
106: pcctwoattach(parent, self, args)
107: struct device *parent, *self;
108: void *args;
109: {
110: struct confargs *ca = args;
111: struct pcctwosoftc *sc = (struct pcctwosoftc *)self;
112: bus_space_handle_t ioh;
113: u_int8_t genctl;
114:
115: sc->sc_base = PCC2_BASE;
116:
117: if (bus_space_map(ca->ca_iot, sc->sc_base, PCC2_SIZE, 0, &ioh) != 0) {
118: printf(": can't map registers!\n");
119: return;
120: }
121:
122: sc->sc_iot = ca->ca_iot;
123: sc->sc_ioh = ioh;
124:
125: bus_space_write_1(sc->sc_iot, ioh, PCCTWO_VECBASE, PCC2_VECBASE);
126: genctl = bus_space_read_1(sc->sc_iot, ioh, PCCTWO_GENCTL);
127: #if NBUSSW > 0
128: if (ca->ca_bustype == BUS_BUSSWITCH) {
129: /* Make sure the bus is mc68040 compatible */
130: genctl |= PCC2_GENCTL_C040;
131: }
132: #endif
133: genctl |= PCC2_GENCTL_IEN; /* global irq enable */
134: bus_space_write_1(sc->sc_iot, ioh, PCCTWO_GENCTL, genctl);
135:
136: printf(": rev %d\n",
137: bus_space_read_1(sc->sc_iot, ioh, PCCTWO_CHIPREV));
138:
139: config_search(pcctwo_scan, self, args);
140: }
141:
142: int
143: pcctwo_print(args, bus)
144: void *args;
145: const char *bus;
146: {
147: struct confargs *ca = args;
148:
149: if (ca->ca_offset != -1)
150: printf(" offset 0x%x", ca->ca_offset);
151: if (ca->ca_ipl > 0)
152: printf(" ipl %d", ca->ca_ipl);
153: return (UNCONF);
154: }
155:
156: int
157: pcctwo_scan(parent, child, args)
158: struct device *parent;
159: void *child, *args;
160: {
161: struct cfdata *cf = child;
162: struct confargs oca, *ca = args;
163:
164: bzero(&oca, sizeof oca);
165: oca.ca_iot = ca->ca_iot;
166: oca.ca_dmat = ca->ca_dmat;
167: oca.ca_offset = cf->cf_loc[0];
168: oca.ca_ipl = cf->cf_loc[1];
169: if (oca.ca_offset != -1) {
170: /* offset locator for pcctwo children is relative to segment */
171: oca.ca_paddr = ca->ca_paddr + oca.ca_offset;
172: } else {
173: oca.ca_paddr = -1;
174: }
175: oca.ca_bustype = BUS_PCCTWO;
176: oca.ca_name = cf->cf_driver->cd_name;
177: if ((*cf->cf_attach->ca_match)(parent, cf, &oca) == 0)
178: return (0);
179: config_attach(parent, cf, &oca, pcctwo_print);
180: return (1);
181: }
182:
183: /*
184: * PCC2 interrupts land in a PCC2_NVEC sized hole starting at PCC2_VECBASE
185: */
186: int
187: pcctwointr_establish(int vec, struct intrhand *ih, const char *name)
188: {
189: #ifdef DIAGNOSTIC
190: if (vec < 0 || vec >= PCC2_NVEC)
191: panic("pcctwo_establish: illegal vector 0x%x", vec);
192: #endif
193:
194: return intr_establish(PCC2_VECBASE + vec, ih, name);
195: }
CVSweb