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