1/* 2 * ISA Plug & Play support 3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz> 4 * 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * 20 */ 21 22#ifndef LINUX_ISAPNP_H 23#define LINUX_ISAPNP_H 24 25#include <linux/config.h> 26#include <linux/errno.h> 27 28/* 29 * Configuration registers (TODO: change by specification) 30 */ 31 32#define ISAPNP_CFG_ACTIVATE 0x30 /* byte */ 33#define ISAPNP_CFG_MEM 0x40 /* 4 * dword */ 34#define ISAPNP_CFG_PORT 0x60 /* 8 * word */ 35#define ISAPNP_CFG_IRQ 0x70 /* 2 * word */ 36#define ISAPNP_CFG_DMA 0x74 /* 2 * byte */ 37 38/* 39 * 40 */ 41 42#define ISAPNP_VENDOR(a,b,c) (((((a)-'A'+1)&0x3f)<<2)|\ 43 ((((b)-'A'+1)&0x18)>>3)|((((b)-'A'+1)&7)<<13)|\ 44 ((((c)-'A'+1)&0x1f)<<8)) 45#define ISAPNP_DEVICE(x) ((((x)&0xf000)>>8)|\ 46 (((x)&0x0f00)>>8)|\ 47 (((x)&0x00f0)<<8)|\ 48 (((x)&0x000f)<<8)) 49#define ISAPNP_FUNCTION(x) ISAPNP_DEVICE(x) 50 51/* 52 * 53 */ 54 55#ifdef __KERNEL__ 56 57#include <linux/pci.h> 58 59#define ISAPNP_PORT_FLAG_16BITADDR (1<<0) 60#define ISAPNP_PORT_FLAG_FIXED (1<<1) 61 62struct isapnp_port { 63 unsigned short min; /* min base number */ 64 unsigned short max; /* max base number */ 65 unsigned char align; /* align boundary */ 66 unsigned char size; /* size of range */ 67 unsigned char flags; /* port flags */ 68 unsigned char pad; /* pad */ 69 struct isapnp_resources *res; /* parent */ 70 struct isapnp_port *next; /* next port */ 71}; 72 73struct isapnp_irq { 74 unsigned short map; /* bitmaks for IRQ lines */ 75 unsigned char flags; /* IRQ flags */ 76 unsigned char pad; /* pad */ 77 struct isapnp_resources *res; /* parent */ 78 struct isapnp_irq *next; /* next IRQ */ 79}; 80 81struct isapnp_dma { 82 unsigned char map; /* bitmask for DMA channels */ 83 unsigned char flags; /* DMA flags */ 84 struct isapnp_resources *res; /* parent */ 85 struct isapnp_dma *next; /* next port */ 86}; 87 88struct isapnp_mem { 89 unsigned int min; /* min base number */ 90 unsigned int max; /* max base number */ 91 unsigned int align; /* align boundary */ 92 unsigned int size; /* size of range */ 93 unsigned char flags; /* memory flags */ 94 unsigned char pad; /* pad */ 95 struct isapnp_resources *res; /* parent */ 96 struct isapnp_mem *next; /* next memory resource */ 97}; 98 99struct isapnp_mem32 { 100 /* TODO */ 101 unsigned char data[17]; 102 struct isapnp_resources *res; /* parent */ 103 struct isapnp_mem32 *next; /* next 32-bit memory resource */ 104}; 105 106struct isapnp_fixup { 107 unsigned short vendor; /* matching vendor */ 108 unsigned short device; /* matching device */ 109 void (*quirk_function)(struct pci_dev *dev); /* fixup function */ 110}; 111 112 113#define ISAPNP_RES_PRIORITY_PREFERRED 0 114#define ISAPNP_RES_PRIORITY_ACCEPTABLE 1 115#define ISAPNP_RES_PRIORITY_FUNCTIONAL 2 116#define ISAPNP_RES_PRIORITY_INVALID 65535 117 118struct isapnp_resources { 119 unsigned short priority; /* priority */ 120 unsigned short dependent; /* dependent resources */ 121 struct isapnp_port *port; /* first port */ 122 struct isapnp_irq *irq; /* first IRQ */ 123 struct isapnp_dma *dma; /* first DMA */ 124 struct isapnp_mem *mem; /* first memory resource */ 125 struct isapnp_mem32 *mem32; /* first 32-bit memory */ 126 struct pci_dev *dev; /* parent */ 127 struct isapnp_resources *alt; /* alternative resource (aka dependent resources) */ 128 struct isapnp_resources *next; /* next resource */ 129}; 130 131#define ISAPNP_ANY_ID 0xffff 132#define ISAPNP_CARD_DEVS 8 133 134#define ISAPNP_CARD_ID(_va, _vb, _vc, _device) \ 135 card_vendor: ISAPNP_VENDOR(_va, _vb, _vc), card_device: ISAPNP_DEVICE(_device) 136#define ISAPNP_CARD_END \ 137 card_vendor: 0, card_device: 0 138#define ISAPNP_DEVICE_ID(_va, _vb, _vc, _function) \ 139 { vendor: ISAPNP_VENDOR(_va, _vb, _vc), function: ISAPNP_FUNCTION(_function) } 140 141/* export used IDs outside module */ 142#define ISAPNP_CARD_TABLE(name) \ 143 MODULE_GENERIC_TABLE(isapnp_card, name) 144 145struct isapnp_card_id { 146 unsigned long driver_data; /* data private to the driver */ 147 unsigned short card_vendor, card_device; 148 struct { 149 unsigned short vendor, function; 150 } devs[ISAPNP_CARD_DEVS]; /* logical devices */ 151}; 152 153#define ISAPNP_DEVICE_SINGLE(_cva, _cvb, _cvc, _cdevice, _dva, _dvb, _dvc, _dfunction) \ 154 card_vendor: ISAPNP_VENDOR(_cva, _cvb, _cvc), card_device: ISAPNP_DEVICE(_cdevice), \ 155 vendor: ISAPNP_VENDOR(_dva, _dvb, _dvc), function: ISAPNP_FUNCTION(_dfunction) 156#define ISAPNP_DEVICE_SINGLE_END \ 157 card_vendor: 0, card_device: 0 158 159struct isapnp_device_id { 160 unsigned short card_vendor, card_device; 161 unsigned short vendor, function; 162 unsigned long driver_data; /* data private to the driver */ 163}; 164 165struct isapnp_driver { 166 struct list_head node; 167 char *name; 168 const struct isapnp_device_id *id_table; /* NULL if wants all devices */ 169 int (*probe) (struct pci_dev *dev, const struct isapnp_device_id *id); /* New device inserted */ 170 void (*remove) (struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */ 171}; 172 173#if defined(CONFIG_ISAPNP) || (defined(CONFIG_ISAPNP_MODULE) && defined(MODULE)) 174 175#define __ISAPNP__ 176 177/* lowlevel configuration */ 178int isapnp_present(void); 179int isapnp_cfg_begin(int csn, int device); 180int isapnp_cfg_end(void); 181unsigned char isapnp_read_byte(unsigned char idx); 182unsigned short isapnp_read_word(unsigned char idx); 183unsigned int isapnp_read_dword(unsigned char idx); 184void isapnp_write_byte(unsigned char idx, unsigned char val); 185void isapnp_write_word(unsigned char idx, unsigned short val); 186void isapnp_write_dword(unsigned char idx, unsigned int val); 187void isapnp_wake(unsigned char csn); 188void isapnp_device(unsigned char device); 189void isapnp_activate(unsigned char device); 190void isapnp_deactivate(unsigned char device); 191void isapnp_fixup_device(struct pci_dev *dev); 192void *isapnp_alloc(long size); 193int isapnp_proc_init(void); 194int isapnp_proc_done(void); 195/* manager */ 196struct pci_bus *isapnp_find_card(unsigned short vendor, 197 unsigned short device, 198 struct pci_bus *from); 199struct pci_dev *isapnp_find_dev(struct pci_bus *card, 200 unsigned short vendor, 201 unsigned short function, 202 struct pci_dev *from); 203int isapnp_probe_cards(const struct isapnp_card_id *ids, 204 int (*probe)(struct pci_bus *card, 205 const struct isapnp_card_id *id)); 206int isapnp_probe_devs(const struct isapnp_device_id *ids, 207 int (*probe)(struct pci_dev *dev, 208 const struct isapnp_device_id *id)); 209/* misc */ 210void isapnp_resource_change(struct resource *resource, 211 unsigned long start, 212 unsigned long size); 213int isapnp_activate_dev(struct pci_dev *dev, const char *name); 214/* init/main.c */ 215int isapnp_init(void); 216 217extern struct list_head isapnp_cards; 218extern struct list_head isapnp_devices; 219 220#define isapnp_for_each_card(card) \ 221 for(card = pci_bus_b(isapnp_cards.next); card != pci_bus_b(&isapnp_cards); card = pci_bus_b(card->node.next)) 222#define isapnp_for_each_dev(dev) \ 223 for(dev = pci_dev_g(isapnp_devices.next); dev != pci_dev_g(&isapnp_devices); dev = pci_dev_g(dev->global_list.next)) 224 225int isapnp_register_driver(struct isapnp_driver *drv); 226void isapnp_unregister_driver(struct isapnp_driver *drv); 227 228#else /* !CONFIG_ISAPNP */ 229 230/* lowlevel configuration */ 231static inline int isapnp_present(void) { return 0; } 232static inline int isapnp_cfg_begin(int csn, int device) { return -ENODEV; } 233static inline int isapnp_cfg_end(void) { return -ENODEV; } 234static inline unsigned char isapnp_read_byte(unsigned char idx) { return 0xff; } 235static inline unsigned short isapnp_read_word(unsigned char idx) { return 0xffff; } 236static inline unsigned int isapnp_read_dword(unsigned char idx) { return 0xffffffff; } 237static inline void isapnp_write_byte(unsigned char idx, unsigned char val) { ; } 238static inline void isapnp_write_word(unsigned char idx, unsigned short val) { ; } 239static inline void isapnp_write_dword(unsigned char idx, unsigned int val) { ; } 240static inline void isapnp_wake(unsigned char csn) { ; } 241static inline void isapnp_device(unsigned char device) { ; } 242static inline void isapnp_activate(unsigned char device) { ; } 243static inline void isapnp_deactivate(unsigned char device) { ; } 244/* manager */ 245static inline struct pci_bus *isapnp_find_card(unsigned short vendor, 246 unsigned short device, 247 struct pci_bus *from) { return NULL; } 248static inline struct pci_dev *isapnp_find_dev(struct pci_bus *card, 249 unsigned short vendor, 250 unsigned short function, 251 struct pci_dev *from) { return NULL; } 252static inline int isapnp_probe_cards(const struct isapnp_card_id *ids, 253 int (*probe)(struct pci_bus *card, 254 const struct isapnp_card_id *id)) { return -ENODEV; } 255static inline int isapnp_probe_devs(const struct isapnp_device_id *ids, 256 int (*probe)(struct pci_dev *dev, 257 const struct isapnp_device_id *id)) { return -ENODEV; } 258static inline void isapnp_resource_change(struct resource *resource, 259 unsigned long start, 260 unsigned long size) { ; } 261static inline int isapnp_activate_dev(struct pci_dev *dev, const char *name) { return -ENODEV; } 262 263static inline int isapnp_register_driver(struct isapnp_driver *drv) { return 0; } 264 265static inline void isapnp_unregister_driver(struct isapnp_driver *drv) { } 266 267#endif /* CONFIG_ISAPNP */ 268 269#endif /* __KERNEL__ */ 270#endif /* LINUX_ISAPNP_H */ 271