Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / hp700 / dev / wax.c
bloba1b8d16d6002ee339d0f1b338744a3246b65c2db
1 /* $NetBSD: wax.c,v 1.13 2009/05/24 06:53:34 skrll Exp $ */
3 /* $OpenBSD: wax.c,v 1.1 1998/11/23 03:04:10 mickey Exp $ */
5 /*
6 * Copyright (c) 1998-2003 Michael Shalayeff
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: wax.c,v 1.13 2009/05/24 06:53:34 skrll Exp $");
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37 #include <sys/reboot.h>
39 #include <machine/iomod.h>
40 #include <machine/autoconf.h>
42 #include <hp700/dev/cpudevs.h>
44 #include <hp700/gsc/gscbusvar.h>
46 #define WAX_IOMASK 0xfff00000
47 #define WAX_REGS 0xc000
49 struct wax_regs {
50 uint32_t wax_irr; /* int requset register */
51 uint32_t wax_imr; /* int mask register */
52 uint32_t wax_ipr; /* int pending register */
53 uint32_t wax_icr; /* int control register */
54 uint32_t wax_iar; /* int address register */
57 struct wax_softc {
58 device_t sc_dv;
59 struct hp700_int_reg sc_int_reg;
60 struct wax_regs volatile *sc_regs;
63 int waxmatch(device_t, cfdata_t, void *);
64 void waxattach(device_t, device_t, void *);
67 CFATTACH_DECL_NEW(wax, sizeof(struct wax_softc),
68 waxmatch, waxattach, NULL, NULL);
70 static int wax_attached;
73 * Before a module is matched, this fixes up its gsc_attach_args.
75 static void wax_fix_args(void *, struct gsc_attach_args *);
76 static void
77 wax_fix_args(void *_sc, struct gsc_attach_args *ga)
79 struct wax_softc *sc = _sc;
80 hppa_hpa_t module_offset;
83 * Determine this module's interrupt bit.
85 module_offset = ga->ga_hpa - (hppa_hpa_t) sc->sc_regs;
86 ga->ga_irq = HP700CF_IRQ_UNDEF;
87 if (module_offset == 0x1000) /* hil */
88 ga->ga_irq = 1;
89 if (module_offset == 0x2000) /* com */
90 ga->ga_irq = 6;
93 int
94 waxmatch(device_t parent, cfdata_t cf, void *aux)
96 struct confargs *ca = aux;
98 /* there will be only one */
99 if (wax_attached ||
100 ca->ca_type.iodc_type != HPPA_TYPE_BHA ||
101 ca->ca_type.iodc_sv_model != HPPA_BHA_WAX)
102 return 0;
104 /* Make sure we have an IRQ. */
105 if (ca->ca_irq == HP700CF_IRQ_UNDEF) {
106 ca->ca_irq = hp700_intr_allocate_bit(&int_reg_cpu);
109 return 1;
112 void
113 waxattach(device_t parent, device_t self, void *aux)
115 struct confargs *ca = aux;
116 struct wax_softc *sc = device_private(self);
117 struct gsc_attach_args ga;
118 bus_space_handle_t ioh;
119 int s, in;
121 if (ca->ca_irq == HP700CF_IRQ_UNDEF) {
122 aprint_error(": can't allocate IRQ\n");
123 return;
126 sc->sc_dv = self;
127 wax_attached = 1;
129 aprint_normal("\n");
132 * Map the WAX interrupt registers.
134 if (bus_space_map(ca->ca_iot, ca->ca_hpa, sizeof(struct wax_regs),
135 0, &ioh))
136 panic("waxattach: can't map interrupt registers");
137 sc->sc_regs = (struct wax_regs *)ca->ca_hpa;
139 /* interrupts guts */
140 s = splhigh();
141 sc->sc_regs->wax_iar = cpu_gethpa(0) | (31 - ca->ca_irq);
142 sc->sc_regs->wax_icr = 0;
143 sc->sc_regs->wax_imr = ~0U;
144 in = sc->sc_regs->wax_irr;
145 sc->sc_regs->wax_imr = 0;
146 splx(s);
148 /* Establish the interrupt register. */
149 hp700_intr_reg_establish(&sc->sc_int_reg);
150 sc->sc_int_reg.int_reg_mask = &sc->sc_regs->wax_imr;
151 sc->sc_int_reg.int_reg_req = &sc->sc_regs->wax_irr;
153 /* Attach the GSC bus. */
154 ga.ga_ca = *ca; /* clone from us */
155 if (strcmp(parent->dv_xname, "mainbus0") == 0) {
156 ga.ga_dp.dp_bc[0] = ga.ga_dp.dp_bc[1];
157 ga.ga_dp.dp_bc[1] = ga.ga_dp.dp_bc[2];
158 ga.ga_dp.dp_bc[2] = ga.ga_dp.dp_bc[3];
159 ga.ga_dp.dp_bc[3] = ga.ga_dp.dp_bc[4];
160 ga.ga_dp.dp_bc[4] = ga.ga_dp.dp_bc[5];
161 ga.ga_dp.dp_bc[5] = ga.ga_dp.dp_mod;
162 ga.ga_dp.dp_mod = 0;
165 ga.ga_name = "gsc";
166 ga.ga_int_reg = &sc->sc_int_reg;
167 ga.ga_fix_args = wax_fix_args;
168 ga.ga_fix_args_cookie = sc;
169 ga.ga_scsi_target = 7; /* XXX */
170 config_found(self, &ga, gscprint);