Initial import from FreeBSD RELENG_4:
[games.git] / sys / dev / misc / pcic / i82365var.h
1 /*      $NetBSD: i82365var.h,v 1.8 1999/10/15 06:07:27 haya Exp $       */
2 /* $FreeBSD: src/sys/dev/pcic/i82365var.h,v 1.15.2.1 2000/05/23 03:57:02 imp Exp $ */
3
4 /*
5  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Marc Horowitz.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <dev/pccard/pccardreg.h>
34
35 #include <dev/pcic/i82365reg.h>
36
37 struct proc;
38
39 struct pcic_event {
40         STAILQ_ENTRY(pcic_event) pe_q;
41         int pe_type;
42 };
43
44 /* pe_type */
45 #define PCIC_EVENT_INSERTION    0
46 #define PCIC_EVENT_REMOVAL      1
47
48 struct pcic_handle {
49         struct pcic_softc *sc;
50         device_t dev;
51         bus_space_tag_t ph_bus_t;       /* I/O or MEM?  I don't mind */
52         bus_space_handle_t ph_bus_h;
53         u_int8_t (* ph_read)(struct pcic_handle*, int);
54         void (* ph_write)(struct pcic_handle *, int, u_int8_t);
55
56         int     vendor;
57         int     sock;
58         int     flags;
59         int laststate;
60         int     memalloc;
61         struct pccard_mem_handle mem[PCIC_MEM_WINS];    /* XXX BAD XXX */
62         int     ioalloc;
63         struct pccard_io_handle io[PCIC_IO_WINS];       /* XXX BAD XXX */
64         int     ih_irq;
65
66         int shutdown;
67         struct proc *event_thread;
68         STAILQ_HEAD(, pcic_event) events;
69 };
70
71 #define PCIC_FLAG_SOCKETP       0x0001
72 #define PCIC_FLAG_CARDP         0x0002
73
74 #define PCIC_LASTSTATE_PRESENT  0x0002
75 #define PCIC_LASTSTATE_HALF             0x0001
76 #define PCIC_LASTSTATE_EMPTY    0x0000
77
78 #define C0SA PCIC_CHIP0_BASE+PCIC_SOCKETA_INDEX
79 #define C0SB PCIC_CHIP0_BASE+PCIC_SOCKETB_INDEX
80 #define C1SA PCIC_CHIP1_BASE+PCIC_SOCKETA_INDEX
81 #define C1SB PCIC_CHIP1_BASE+PCIC_SOCKETB_INDEX
82
83 /*
84  * This is sort of arbitrary.  It merely needs to be "enough". It can be
85  * overridden in the conf file, anyway.
86  */
87
88 #define PCIC_MEM_PAGES  4
89 #define PCIC_MEMSIZE    PCIC_MEM_PAGES*PCIC_MEM_PAGESIZE
90
91 #define PCIC_NSLOTS     4
92
93 struct pcic_softc {
94         device_t dev;
95
96         bus_space_tag_t memt;
97         bus_space_handle_t memh;
98         bus_space_tag_t iot;
99         bus_space_handle_t ioh;
100
101         void            *intrhand;
102         struct resource *irq_res;
103         int             irq_rid;
104         struct resource *mem_res;
105         int             mem_rid;
106         struct resource *port_res;
107         int             port_rid;
108
109 #define PCIC_MAX_MEM_PAGES      (8 * sizeof(int))
110
111         /* used by memory window mapping functions */
112         bus_addr_t membase;
113
114         /*
115          * used by io window mapping functions.  These can actually overlap
116          * with another pcic, since the underlying extent mapper will deal
117          * with individual allocations.  This is here to deal with the fact
118          * that different busses have different real widths (different pc
119          * hardware seems to use 10 or 12 bits for the I/O bus).
120          */
121         bus_addr_t iobase;
122         bus_addr_t iosize;
123
124         int     irq;
125         void    *ih;
126
127         struct pcic_handle handle[PCIC_NSLOTS];
128 };
129
130
131 int     pcic_ident_ok(int);
132 int     pcic_vendor(struct pcic_handle *);
133 char    *pcic_vendor_to_string(int);
134
135 int     pcic_attach(device_t dev);
136
137 #if 0
138
139 static __inline int pcic_read(struct pcic_handle *, int);
140 static __inline int
141 pcic_read(h, idx)
142         struct pcic_handle *h;
143         int idx;
144 {
145         if (idx != -1)
146                 bus_space_write_1(h->sc->iot, h->sc->ioh, PCIC_REG_INDEX,
147                     h->sock + idx);
148         return (bus_space_read_1(h->sc->iot, h->sc->ioh, PCIC_REG_DATA));
149 }
150
151 static __inline void pcic_write(struct pcic_handle *, int, int);
152 static __inline void
153 pcic_write(h, idx, data)
154         struct pcic_handle *h;
155         int idx;
156         int data;
157 {
158         if (idx != -1)
159                 bus_space_write_1(h->sc->iot, h->sc->ioh, PCIC_REG_INDEX,
160                     h->sock + idx);
161         bus_space_write_1(h->sc->iot, h->sc->ioh, PCIC_REG_DATA, (data));
162 }
163 #else
164 #define pcic_read(h, idx) \
165         (*(h)->ph_read)((h), (idx))
166
167 #define pcic_write(h, idx, data) \
168         (*(h)->ph_write)((h), (idx), (data))
169
170 #endif
171
172 /*
173  * bus/device/etc routines
174  */
175 int pcic_activate_resource(device_t dev, device_t child, int type, int rid,
176     struct resource *r);
177 struct resource *pcic_alloc_resource(device_t dev, device_t child, int type,
178     int *rid, u_long start, u_long end, u_long count, u_int flags);
179 int pcic_deactivate_resource(device_t dev, device_t child, int type, int rid,
180     struct resource *r);
181 int pcic_release_resource(device_t dev, device_t child, int type, int rid,
182     struct resource *r);
183 int pcic_setup_intr(device_t dev, device_t child, struct resource *irq,
184     int flags, driver_intr_t intr, void *arg, void **cookiep);
185 int pcic_teardown_intr(device_t dev, device_t child, struct resource *irq,
186     void *cookiep);
187 int pcic_suspend(device_t dev);
188 int pcic_resume(device_t dev);
189 int pcic_enable_socket(device_t dev, device_t child);
190 int pcic_disable_socket(device_t dev, device_t child);
191 int pcic_set_res_flags(device_t dev, device_t child, int type, int rid, 
192     u_int32_t flags);
193 int pcic_set_memory_offset(device_t dev, device_t child, int rid,
194     u_int32_t offset);