Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / bus / pccard / pcicvar.h
1 /*
2  * Copyright (c) 2001 M. Warner Losh.  All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  * $FreeBSD: src/sys/pccard/pcicvar.h,v 1.15.2.11 2002/09/22 20:26:58 imp Exp $
25  */
26
27 /*
28  *      Per-slot data table.
29  */
30 struct pcic_slot {
31         int offset;                     /* Offset value for index */
32         char controller;                /* Device type */
33         char revision;                  /* Device Revision */
34         struct slot *slt;               /* Back ptr to slot */
35         struct pcic_softc *sc;          /* Back pointer to softc */
36         u_int8_t (*getb)(struct pcic_slot *, int);
37         void   (*putb)(struct pcic_slot *, int, u_int8_t);
38         bus_space_tag_t bst;
39         bus_space_handle_t bsh;
40 };
41
42 enum pcic_intr_way { pcic_iw_isa = 1, pcic_iw_pci = 2 };
43
44 struct pcic_softc 
45 {
46         u_int32_t               slotmask;/* Mask of valid slots */
47         u_int32_t               flags;  /* Interesting flags */
48 #define PCIC_AB_POWER      0x00000001   /* Use old A/B step power */
49 #define PCIC_DF_POWER      0x00000002   /* Uses DF step regs  */
50 #define PCIC_PD_POWER      0x00000004   /* Uses CL-PD regs  */
51 #define PCIC_VG_POWER      0x00000008   /* Uses VG power regs */
52 #define PCIC_KING_POWER    0x00000010   /* Uses IBM KING regs  */
53 #define PCIC_RICOH_POWER   0x00000020   /* Uses the ricoh power regs */
54 #define PCIC_CARDBUS_POWER 0x00000040   /* Cardbus power regs */
55 #define PCIC_YENTA_HIGH_MEMORY 0x0080   /* Can do high memory mapping */
56
57         enum pcic_intr_way      csc_route; /* How to route csc interrupts */
58         enum pcic_intr_way      func_route; /* How to route function ints */
59         int                     iorid;  /* Rid of I/O region */
60         struct resource         *iores; /* resource for I/O region */
61         int                     memrid; /* Memory rid */
62         struct resource         *memres;/* Resource for memory mapped regs */
63         int                     irqrid; /* Irq rid */
64         struct resource         *irqres;/* Irq resource */
65         void                    *ih;    /* Our interrupt handler. */
66         int                     irq;
67         device_t                dev;    /* Our device */
68         void (*slot_poll)(void *);
69         struct callout_handle   timeout_ch;
70         struct pcic_slot        slots[PCIC_MAX_SLOTS];
71         int                     cd_pending; /* debounce timeout active */
72         int                     cd_present; /* debounced card-present state */
73         struct callout_handle   cd_ch;  /* handle for pcic_cd_insert */
74         struct pcic_chip        *chip;
75         driver_intr_t           *func_intr;
76         void                    *func_arg;
77 };
78
79 typedef int (pcic_intr_way_t)(struct pcic_slot *, enum pcic_intr_way);
80 typedef int (pcic_intr_mapirq_t)(struct pcic_slot *, int irq);
81 typedef void (pcic_init_t)(device_t);
82
83 struct pcic_chip
84 {
85         pcic_intr_way_t *func_intr_way;
86         pcic_intr_way_t *csc_intr_way;
87         pcic_intr_mapirq_t *map_irq;
88         pcic_init_t     *init;
89 };
90
91 extern devclass_t       pcic_devclass;
92 extern int              pcic_override_irq;
93
94 int pcic_activate_resource(device_t dev, device_t child, int type, int rid,
95     struct resource *r);
96 struct resource *pcic_alloc_resource(device_t dev, device_t child, int type,
97     int *rid, u_long start, u_long end, u_long count, u_int flags);
98 int pcic_attach(device_t dev);
99 void pcic_clrb(struct pcic_slot *sp, int reg, unsigned char mask);
100 int pcic_deactivate_resource(device_t dev, device_t child, int type, int rid,
101     struct resource *r);
102 void pcic_dealloc(device_t dev);
103 void pcic_do_stat_delta(struct pcic_slot *sp);
104 int pcic_get_memory_offset(device_t bus, device_t child, int rid,
105     u_int32_t *offset);
106 int pcic_get_res_flags(device_t bus, device_t child, int restype, int rid,
107     u_long *value);
108 unsigned char pcic_getb_io(struct pcic_slot *sp, int reg);
109 driver_intr_t   pcic_isa_intr;
110 int             pcic_isa_intr1(void *);
111 pcic_intr_mapirq_t pcic_isa_mapirq;
112 void pcic_putb_io(struct pcic_slot *sp, int reg, unsigned char val);
113 int pcic_set_memory_offset(device_t bus, device_t child, int rid,
114     u_int32_t offset
115 #if __FreeBSD_version >= 500000
116     , u_int32_t *deltap
117 #endif
118     );
119 int pcic_set_res_flags(device_t bus, device_t child, int restype, int rid,
120     u_long value);
121 void pcic_setb(struct pcic_slot *sp, int reg, unsigned char mask);
122 int pcic_setup_intr(device_t dev, device_t child, struct resource *irq,
123     int flags, driver_intr_t *intr, void *arg, void **cookiep);
124 int pcic_teardown_intr(device_t dev, device_t child, struct resource *irq,
125     void *cookie);
126 timeout_t       pcic_timeout;