Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / bus / cam / scsi / scsi_low_pisa.c
1 /*      $FreeBSD: src/sys/cam/scsi/scsi_low_pisa.c,v 1.2.2.4 2001/12/17 13:30:20 non Exp $      */
2 /*      $NecBSD: scsi_low_pisa.c,v 1.13 1998/11/26 14:26:11 honda Exp $ */
3 /*      $NetBSD$        */
4
5 /*
6  * [NetBSD for NEC PC-98 series]
7  *  Copyright (c) 1995, 1996, 1997, 1998
8  *      NetBSD/pc98 porting staff. All rights reserved.
9  *  Copyright (c) 1995, 1996, 1997, 1998
10  *      Naofumi HONDA. All rights reserved.
11  * 
12  *  Redistribution and use in source and binary forms, with or without
13  *  modification, are permitted provided that the following conditions
14  *  are met:
15  *  1. Redistributions of source code must retain the above copyright
16  *     notice, this list of conditions and the following disclaimer.
17  *  2. Redistributions in binary form must reproduce the above copyright
18  *     notice, this list of conditions and the following disclaimer in the
19  *     documentation and/or other materials provided with the distribution.
20  *  3. The name of the author may not be used to endorse or promote products
21  *     derived from this software without specific prior written permission.
22  * 
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 #ifdef  __NetBSD__
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/device.h>
41 #include <sys/errno.h>
42
43 #include <machine/bus.h>
44 #include <machine/intr.h>
45
46 #include <dev/isa/isareg.h>
47 #include <dev/isa/isavar.h>
48
49 #include <dev/isa/pisaif.h>
50
51 #include <machine/dvcfg.h>
52
53 #include <dev/scsipi/scsi_all.h>
54 #include <dev/scsipi/scsipi_all.h>
55 #include <dev/scsipi/scsiconf.h>
56 #include <dev/scsipi/scsi_disk.h>
57
58 #include <i386/Cbus/dev/scsi_low.h>
59 #include <i386/Cbus/dev/scsi_low_pisa.h>
60
61 #define SCSIBUS_RESCAN
62
63 int
64 scsi_low_deactivate_pisa(dh)
65         pisa_device_handle_t dh;
66 {
67         struct scsi_low_softc *sc = PISA_DEV_SOFTC(dh);
68
69         if (scsi_low_deactivate(sc) != 0)
70                 return EBUSY;
71         return 0;
72 }
73
74 int
75 scsi_low_activate_pisa(dh)
76         pisa_device_handle_t dh;
77 {
78         struct scsi_low_softc *sc = PISA_DEV_SOFTC(dh);
79         slot_device_res_t dr = PISA_RES_DR(dh);
80
81         sc->sl_cfgflags = DVCFG_MKCFG(DVCFG_MAJOR(sc->sl_cfgflags), \
82                                       DVCFG_MINOR(PISA_DR_DVCFG(dr)));
83         sc->sl_irq = PISA_DR_IRQ(dr);
84
85         if (scsi_low_activate(sc) != 0)
86                 return EBUSY;
87
88         /* rescan the scsi bus */
89 #ifdef  SCSIBUS_RESCAN
90         if (scsi_low_is_busy(sc) == 0 &&
91             PISA_RES_EVENT(dh) == PISA_EVENT_INSERT)
92                 scsi_probe_busses((int) sc->sl_si.si_splp->scsipi_scsi.scsibus,
93                                   -1, -1);
94 #endif
95         return 0;
96 }
97
98 int
99 scsi_low_notify_pisa(dh, ev)
100         pisa_device_handle_t dh;
101         pisa_event_t ev;
102 {
103         struct scsi_low_softc *sc = PISA_DEV_SOFTC(dh);
104
105         switch(ev)
106         {
107         case PISA_EVENT_QUERY_SUSPEND:
108                 if (scsi_low_is_busy(sc) != 0)
109                         return SD_EVENT_STATUS_BUSY;
110                 break;
111
112         default:
113                 break;
114         }
115         return 0;
116 }
117 #endif  /* __NetBSD__ */
118
119 #ifdef  __FreeBSD__ 
120 #include <sys/param.h>
121 #include <sys/systm.h>
122 #include <sys/kernel.h>
123 #if __FreeBSD_version >= 500001
124 #include <sys/bio.h>
125 #endif
126 #include <sys/buf.h>
127 #include <sys/queue.h>
128 #include <sys/device_port.h>
129 #include <sys/module.h>
130
131 #include <cam/scsi/scsi_low.h>
132 #include <cam/scsi/scsi_low_pisa.h>
133
134 int
135 scsi_low_deactivate_pisa(sc)
136         struct scsi_low_softc *sc;
137 {
138
139         if (scsi_low_deactivate(sc) != 0)
140                 return EBUSY;
141         return 0;
142 }
143
144 int
145 scsi_low_activate_pisa(sc, flags)
146         struct scsi_low_softc *sc;
147         int flags;
148 {
149
150         sc->sl_cfgflags = ((sc->sl_cfgflags & 0xffff0000) |
151                            (flags & 0x00ff));
152
153         if (scsi_low_activate(sc) != 0)
154                 return EBUSY;
155         return 0;
156 }
157
158 static moduledata_t scsi_low_moduledata = {
159         "scsi_low",
160         NULL,
161         NULL
162 };
163
164 DECLARE_MODULE(scsi_low, scsi_low_moduledata, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
165 MODULE_VERSION(scsi_low, 1);
166 MODULE_DEPEND(scsi_low, cam, 1, 1, 1);
167 #endif  /* __FreeBSD__ */