Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /*
  2  *  linux/zorro.h -- Amiga AutoConfig (Zorro) Bus Definitions
  3  *
  4  *  Copyright (C) 1995--2003 Geert Uytterhoeven
  5  *
  6  *  This file is subject to the terms and conditions of the GNU General Public
  7  *  License.  See the file COPYING in the main directory of this archive
  8  *  for more details.
  9  */
 10 
 11 #ifndef _LINUX_ZORRO_H
 12 #define _LINUX_ZORRO_H
 13 
 14 #ifndef __ASSEMBLY__
 15 
 16 #include <linux/device.h>
 17 
 18 
 19     /*
 20      *  Each Zorro board has a 32-bit ID of the form
 21      *
 22      *      mmmmmmmmmmmmmmmmppppppppeeeeeeee
 23      *
 24      *  with
 25      *
 26      *      mmmmmmmmmmmmmmmm    16-bit Manufacturer ID (assigned by CBM (sigh))
 27      *      pppppppp            8-bit Product ID (assigned by manufacturer)
 28      *      eeeeeeee            8-bit Extended Product ID (currently only used
 29      *                          for some GVP boards)
 30      */
 31 
 32 
 33 #define ZORRO_MANUF(id)         ((id) >> 16)
 34 #define ZORRO_PROD(id)          (((id) >> 8) & 0xff)
 35 #define ZORRO_EPC(id)           ((id) & 0xff)
 36 
 37 #define ZORRO_ID(manuf, prod, epc) \
 38     ((ZORRO_MANUF_##manuf << 16) | ((prod) << 8) | (epc))
 39 
 40 typedef __u32 zorro_id;
 41 
 42 
 43 #define ZORRO_WILDCARD          (0xffffffff)    /* not official */
 44 
 45 /* Include the ID list */
 46 #include <linux/zorro_ids.h>
 47 
 48 
 49     /*
 50      *  GVP identifies most of its products through the 'extended product code'
 51      *  (epc). The epc has to be ANDed with the GVP_PRODMASK before the
 52      *  identification.
 53      */
 54 
 55 #define GVP_PRODMASK                    (0xf8)
 56 #define GVP_SCSICLKMASK                 (0x01)
 57 
 58 enum GVP_flags {
 59     GVP_IO              = 0x01,
 60     GVP_ACCEL           = 0x02,
 61     GVP_SCSI            = 0x04,
 62     GVP_24BITDMA        = 0x08,
 63     GVP_25BITDMA        = 0x10,
 64     GVP_NOBANK          = 0x20,
 65     GVP_14MHZ           = 0x40,
 66 };
 67 
 68 
 69 struct Node {
 70     struct  Node *ln_Succ;      /* Pointer to next (successor) */
 71     struct  Node *ln_Pred;      /* Pointer to previous (predecessor) */
 72     __u8    ln_Type;
 73     __s8    ln_Pri;             /* Priority, for sorting */
 74     __s8    *ln_Name;           /* ID string, null terminated */
 75 } __attribute__ ((packed));
 76 
 77 struct ExpansionRom {
 78     /* -First 16 bytes of the expansion ROM */
 79     __u8  er_Type;              /* Board type, size and flags */
 80     __u8  er_Product;           /* Product number, assigned by manufacturer */
 81     __u8  er_Flags;             /* Flags */
 82     __u8  er_Reserved03;        /* Must be zero ($ff inverted) */
 83     __u16 er_Manufacturer;      /* Unique ID, ASSIGNED BY COMMODORE-AMIGA! */
 84     __u32 er_SerialNumber;      /* Available for use by manufacturer */
 85     __u16 er_InitDiagVec;       /* Offset to optional "DiagArea" structure */
 86     __u8  er_Reserved0c;
 87     __u8  er_Reserved0d;
 88     __u8  er_Reserved0e;
 89     __u8  er_Reserved0f;
 90 } __attribute__ ((packed));
 91 
 92 /* er_Type board type bits */
 93 #define ERT_TYPEMASK    0xc0
 94 #define ERT_ZORROII     0xc0
 95 #define ERT_ZORROIII    0x80
 96 
 97 /* other bits defined in er_Type */
 98 #define ERTB_MEMLIST    5               /* Link RAM into free memory list */
 99 #define ERTF_MEMLIST    (1<<5)
100 
101 struct ConfigDev {
102     struct Node         cd_Node;
103     __u8                cd_Flags;       /* (read/write) */
104     __u8                cd_Pad;         /* reserved */
105     struct ExpansionRom cd_Rom;         /* copy of board's expansion ROM */
106     void                *cd_BoardAddr;  /* where in memory the board was placed */
107     __u32               cd_BoardSize;   /* size of board in bytes */
108     __u16               cd_SlotAddr;    /* which slot number (PRIVATE) */
109     __u16               cd_SlotSize;    /* number of slots (PRIVATE) */
110     void                *cd_Driver;     /* pointer to node of driver */
111     struct ConfigDev    *cd_NextCD;     /* linked list of drivers to config */
112     __u32               cd_Unused[4];   /* for whatever the driver wants */
113 } __attribute__ ((packed));
114 
115 #else /* __ASSEMBLY__ */
116 
117 LN_Succ         = 0
118 LN_Pred         = LN_Succ+4
119 LN_Type         = LN_Pred+4
120 LN_Pri          = LN_Type+1
121 LN_Name         = LN_Pri+1
122 LN_sizeof       = LN_Name+4
123 
124 ER_Type         = 0
125 ER_Product      = ER_Type+1
126 ER_Flags        = ER_Product+1
127 ER_Reserved03   = ER_Flags+1
128 ER_Manufacturer = ER_Reserved03+1
129 ER_SerialNumber = ER_Manufacturer+2
130 ER_InitDiagVec  = ER_SerialNumber+4
131 ER_Reserved0c   = ER_InitDiagVec+2
132 ER_Reserved0d   = ER_Reserved0c+1
133 ER_Reserved0e   = ER_Reserved0d+1
134 ER_Reserved0f   = ER_Reserved0e+1
135 ER_sizeof       = ER_Reserved0f+1
136 
137 CD_Node         = 0
138 CD_Flags        = CD_Node+LN_sizeof
139 CD_Pad          = CD_Flags+1
140 CD_Rom          = CD_Pad+1
141 CD_BoardAddr    = CD_Rom+ER_sizeof
142 CD_BoardSize    = CD_BoardAddr+4
143 CD_SlotAddr     = CD_BoardSize+4
144 CD_SlotSize     = CD_SlotAddr+2
145 CD_Driver       = CD_SlotSize+2
146 CD_NextCD       = CD_Driver+4
147 CD_Unused       = CD_NextCD+4
148 CD_sizeof       = CD_Unused+(4*4)
149 
150 #endif /* __ASSEMBLY__ */
151 
152 #ifndef __ASSEMBLY__
153 
154 #define ZORRO_NUM_AUTO          16
155 
156 #ifdef __KERNEL__
157 
158 #include <linux/init.h>
159 #include <linux/ioport.h>
160 
161 #include <asm/zorro.h>
162 
163 
164     /*
165      *  Zorro devices
166      */
167 
168 struct zorro_dev {
169     struct ExpansionRom rom;
170     zorro_id id;
171     struct zorro_driver *driver;        /* which driver has allocated this device */
172     struct device dev;                  /* Generic device interface */
173     u16 slotaddr;
174     u16 slotsize;
175     char name[64];
176     struct resource resource;
177 };
178 
179 #define to_zorro_dev(n) container_of(n, struct zorro_dev, dev)
180 
181 
182     /*
183      *  Zorro bus
184      */
185 
186 struct zorro_bus {
187     struct list_head devices;           /* list of devices on this bus */
188     unsigned int num_resources;         /* number of resources */
189     struct resource resources[4];       /* address space routed to this bus */
190     struct device dev;
191     char name[10];
192 };
193 
194 extern struct zorro_bus zorro_bus;      /* single Zorro bus */
195 extern struct bus_type zorro_bus_type;
196 
197 
198     /*
199      *  Zorro device IDs
200      */
201 
202 struct zorro_device_id {
203         zorro_id id;                    /* Device ID or ZORRO_WILDCARD */
204         unsigned long driver_data;      /* Data private to the driver */
205 };
206 
207 
208     /*
209      *  Zorro device drivers
210      */
211 
212 struct zorro_driver {
213     struct list_head node;
214     char *name;
215     const struct zorro_device_id *id_table;     /* NULL if wants all devices */
216     int (*probe)(struct zorro_dev *z, const struct zorro_device_id *id);        /* New device inserted */
217     void (*remove)(struct zorro_dev *z);        /* Device removed (NULL if not a hot-plug capable driver) */
218     struct device_driver driver;
219 };
220 
221 #define to_zorro_driver(drv)    container_of(drv, struct zorro_driver, driver)
222 
223 
224 #define zorro_for_each_dev(dev) \
225         for (dev = &zorro_autocon[0]; dev < zorro_autocon+zorro_num_autocon; dev++)
226 
227 
228 /* New-style probing */
229 extern int zorro_register_driver(struct zorro_driver *);
230 extern void zorro_unregister_driver(struct zorro_driver *);
231 extern const struct zorro_device_id *zorro_match_device(const struct zorro_device_id *ids, const struct zorro_dev *z);
232 static inline struct zorro_driver *zorro_dev_driver(const struct zorro_dev *z)
233 {
234     return z->driver;
235 }
236 
237 
238 extern unsigned int zorro_num_autocon;  /* # of autoconfig devices found */
239 extern struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO];
240 
241 
242     /*
243      *  Zorro Functions
244      */
245 
246 extern struct zorro_dev *zorro_find_device(zorro_id id,
247                                            struct zorro_dev *from);
248 
249 #define zorro_resource_start(z) ((z)->resource.start)
250 #define zorro_resource_end(z)   ((z)->resource.end)
251 #define zorro_resource_len(z)   ((z)->resource.end-(z)->resource.start+1)
252 #define zorro_resource_flags(z) ((z)->resource.flags)
253 
254 #define zorro_request_device(z, name) \
255     request_mem_region(zorro_resource_start(z), zorro_resource_len(z), name)
256 #define zorro_release_device(z) \
257     release_mem_region(zorro_resource_start(z), zorro_resource_len(z))
258 
259 /* Similar to the helpers above, these manipulate per-zorro_dev
260  * driver-specific data.  They are really just a wrapper around
261  * the generic device structure functions of these calls.
262  */
263 static inline void *zorro_get_drvdata (struct zorro_dev *z)
264 {
265         return dev_get_drvdata(&z->dev);
266 }
267 
268 static inline void zorro_set_drvdata (struct zorro_dev *z, void *data)
269 {
270         dev_set_drvdata(&z->dev, data);
271 }
272 
273 
274 /*
275  * A helper function which helps ensure correct zorro_driver
276  * setup and cleanup for commonly-encountered hotplug/modular cases
277  *
278  * This MUST stay in a header, as it checks for -DMODULE
279  */
280 static inline int zorro_module_init(struct zorro_driver *drv)
281 {
282         int rc = zorro_register_driver(drv);
283 
284         if (rc > 0)
285                 return 0;
286 
287         /* iff CONFIG_HOTPLUG and built into kernel, we should
288          * leave the driver around for future hotplug events.
289          * For the module case, a hotplug daemon of some sort
290          * should load a module in response to an insert event. */
291 #if defined(CONFIG_HOTPLUG) && !defined(MODULE)
292         if (rc == 0)
293                 return 0;
294 #else
295         if (rc == 0)
296                 rc = -ENODEV;
297 #endif
298 
299         /* if we get here, we need to clean up Zorro driver instance
300          * and return some sort of error */
301         zorro_unregister_driver(drv);
302 
303         return rc;
304 }
305 
306 
307     /*
308      *  Bitmask indicating portions of available Zorro II RAM that are unused
309      *  by the system. Every bit represents a 64K chunk, for a maximum of 8MB
310      *  (128 chunks, physical 0x00200000-0x009fffff).
311      *
312      *  If you want to use (= allocate) portions of this RAM, you should clear
313      *  the corresponding bits.
314      */
315 
316 extern DECLARE_BITMAP(zorro_unused_z2ram, 128);
317 
318 #define Z2RAM_START             (0x00200000)
319 #define Z2RAM_END               (0x00a00000)
320 #define Z2RAM_SIZE              (0x00800000)
321 #define Z2RAM_CHUNKSIZE         (0x00010000)
322 #define Z2RAM_CHUNKMASK         (0x0000ffff)
323 #define Z2RAM_CHUNKSHIFT        (16)
324 
325 
326 #endif /* !__ASSEMBLY__ */
327 #endif /* __KERNEL__ */
328 
329 #endif /* _LINUX_ZORRO_H */
330 
  This page was automatically generated by the LXR engine.