iPXE
isapnp.h
Go to the documentation of this file.
00001 /**************************************************************************
00002 *
00003 *    isapnp.h -- Etherboot isapnp support for the 3Com 3c515
00004 *    Written 2002-2003 by Timothy Legge <tlegge@rogers.com>
00005 *
00006 *    This program is free software; you can redistribute it and/or modify
00007 *    it under the terms of the GNU General Public License as published by
00008 *    the Free Software Foundation; either version 2 of the License, or
00009 *    (at your option) any later version.
00010 *
00011 *    This program is distributed in the hope that it will be useful,
00012 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 *    GNU General Public License for more details.
00015 *
00016 *    You should have received a copy of the GNU General Public License
00017 *    along with this program; if not, write to the Free Software
00018 *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019 *    02110-1301, USA.
00020  *
00021  * You can also choose to distribute this program under the terms of
00022  * the Unmodified Binary Distribution Licence (as given in the file
00023  * COPYING.UBDL), provided that you have satisfied its requirements.
00024 *
00025 *    Portions of this code:
00026 *               Copyright (C) 2001  P.J.H.Fox (fox@roestock.demon.co.uk)
00027 *
00028 *
00029 *
00030 *    REVISION HISTORY:
00031 *    ================
00032 *        Version 0.1 April 26, 2002     TJL
00033 *        Version 0.2 01/08/2003                 TJL Renamed from 3c515_isapnp.h
00034 *
00035 *
00036 *    Generalised into an ISAPnP bus that can be used by more than just
00037 *    the 3c515 by Michael Brown <mbrown@fensystems.co.uk>
00038 *
00039 ***************************************************************************/
00040 
00041 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00042 
00043 #ifndef ISAPNP_H
00044 #define ISAPNP_H
00045 
00046 #include <stdint.h>
00047 #include <ipxe/isa_ids.h>
00048 #include <ipxe/device.h>
00049 #include <ipxe/tables.h>
00050 
00051 /*
00052  * ISAPnP constants
00053  *
00054  */
00055 
00056 /* Port addresses */
00057 #define ISAPNP_ADDRESS          0x279
00058 #define ISAPNP_WRITE_DATA       0xa79
00059 #define ISAPNP_READ_PORT_MIN    0x203
00060 #define ISAPNP_READ_PORT_START  0x213   /* ISAPnP spec says 0x203, but
00061                                          * Linux ISAPnP starts at
00062                                          * 0x213 with no explanatory
00063                                          * comment.  0x203 probably
00064                                          * clashes with something. */
00065 #define ISAPNP_READ_PORT_MAX    0x3ff
00066 #define ISAPNP_READ_PORT_STEP   0x10    /* Can be any multiple of 4
00067                                          * according to the spec, but
00068                                          * since ISA I/O addresses are
00069                                          * allocated in blocks of 16,
00070                                          * it makes no sense to use
00071                                          * any value less than 16.
00072                                          */
00073 
00074 /* Card select numbers */
00075 #define ISAPNP_CSN_MIN          0x01
00076 #define ISAPNP_CSN_MAX          0x0f
00077 
00078 /* Registers */
00079 #define ISAPNP_READPORT                 0x00
00080 #define ISAPNP_SERIALISOLATION          0x01
00081 #define ISAPNP_CONFIGCONTROL            0x02
00082 #define ISAPNP_WAKE                     0x03
00083 #define ISAPNP_RESOURCEDATA             0x04
00084 #define ISAPNP_STATUS                   0x05
00085 #define ISAPNP_CARDSELECTNUMBER         0x06
00086 #define ISAPNP_LOGICALDEVICENUMBER      0x07
00087 #define ISAPNP_ACTIVATE                 0x30
00088 #define ISAPNP_IORANGECHECK             0x31
00089 #define ISAPNP_IOBASE(n)                ( 0x60 + ( (n) * 2 ) )
00090 #define ISAPNP_IRQNO(n)                 ( 0x70 + ( (n) * 2 ) )
00091 #define ISAPNP_IRQTYPE(n)               ( 0x71 + ( (n) * 2 ) )
00092 
00093 /* Bits in the CONFIGCONTROL register */
00094 #define ISAPNP_CONFIG_RESET             ( 1 << 0 )
00095 #define ISAPNP_CONFIG_WAIT_FOR_KEY      ( 1 << 1 )
00096 #define ISAPNP_CONFIG_RESET_CSN         ( 1 << 2 )
00097 #define ISAPNP_CONFIG_RESET_DRV         ( ISAPNP_CONFIG_RESET |         \
00098                                           ISAPNP_CONFIG_WAIT_FOR_KEY |  \
00099                                           ISAPNP_CONFIG_RESET_CSN )
00100 
00101 /* The LFSR used for the initiation key and for checksumming */
00102 #define ISAPNP_LFSR_SEED                0x6a
00103 
00104 /* Small tags */
00105 #define ISAPNP_IS_SMALL_TAG(tag)        ( ! ( (tag) & 0x80 ) )
00106 #define ISAPNP_SMALL_TAG_NAME(tag)      ( ( (tag) >> 3 ) & 0xf )
00107 #define ISAPNP_SMALL_TAG_LEN(tag)       ( ( (tag) & 0x7 ) )
00108 #define ISAPNP_TAG_PNPVERNO             0x01
00109 #define ISAPNP_TAG_LOGDEVID             0x02
00110 #define ISAPNP_TAG_COMPATDEVID          0x03
00111 #define ISAPNP_TAG_IRQ                  0x04
00112 #define ISAPNP_TAG_DMA                  0x05
00113 #define ISAPNP_TAG_STARTDEP             0x06
00114 #define ISAPNP_TAG_ENDDEP               0x07
00115 #define ISAPNP_TAG_IOPORT               0x08
00116 #define ISAPNP_TAG_FIXEDIO              0x09
00117 #define ISAPNP_TAG_RSVDSHORTA           0x0A
00118 #define ISAPNP_TAG_RSVDSHORTB           0x0B
00119 #define ISAPNP_TAG_RSVDSHORTC           0x0C
00120 #define ISAPNP_TAG_RSVDSHORTD           0x0D
00121 #define ISAPNP_TAG_VENDORSHORT          0x0E
00122 #define ISAPNP_TAG_END                  0x0F
00123 /* Large tags */
00124 #define ISAPNP_IS_LARGE_TAG(tag)        ( ( (tag) & 0x80 ) )
00125 #define ISAPNP_LARGE_TAG_NAME(tag)      (tag)
00126 #define ISAPNP_TAG_MEMRANGE             0x81
00127 #define ISAPNP_TAG_ANSISTR              0x82
00128 #define ISAPNP_TAG_UNICODESTR           0x83
00129 #define ISAPNP_TAG_VENDORLONG           0x84
00130 #define ISAPNP_TAG_MEM32RANGE           0x85
00131 #define ISAPNP_TAG_FIXEDMEM32RANGE      0x86
00132 #define ISAPNP_TAG_RSVDLONG0            0xF0
00133 #define ISAPNP_TAG_RSVDLONG1            0xF1
00134 #define ISAPNP_TAG_RSVDLONG2            0xF2
00135 #define ISAPNP_TAG_RSVDLONG3            0xF3
00136 #define ISAPNP_TAG_RSVDLONG4            0xF4
00137 #define ISAPNP_TAG_RSVDLONG5            0xF5
00138 #define ISAPNP_TAG_RSVDLONG6            0xF6
00139 #define ISAPNP_TAG_RSVDLONG7            0xF7
00140 #define ISAPNP_TAG_RSVDLONG8            0xF8
00141 #define ISAPNP_TAG_RSVDLONG9            0xF9
00142 #define ISAPNP_TAG_RSVDLONGA            0xFA
00143 #define ISAPNP_TAG_RSVDLONGB            0xFB
00144 #define ISAPNP_TAG_RSVDLONGC            0xFC
00145 #define ISAPNP_TAG_RSVDLONGD            0xFD
00146 #define ISAPNP_TAG_RSVDLONGE            0xFE
00147 #define ISAPNP_TAG_RSVDLONGF            0xFF
00148 #define ISAPNP_TAG_PSEUDO_NEWBOARD      0x100
00149 
00150 /** An ISAPnP serial identifier */
00151 struct isapnp_identifier {
00152         /** Vendor ID */
00153         uint16_t vendor_id;
00154         /** Product ID */
00155         uint16_t prod_id;
00156         /** Serial number */
00157         uint32_t serial;
00158         /** Checksum */
00159         uint8_t checksum;
00160 } __attribute__ (( packed ));
00161 
00162 /** An ISAPnP logical device ID structure */
00163 struct isapnp_logdevid {
00164         /** Vendor ID */
00165         uint16_t vendor_id;
00166         /** Product ID */
00167         uint16_t prod_id;
00168         /** Flags */
00169         uint16_t flags;
00170 } __attribute__ (( packed ));
00171 
00172 /** An ISAPnP device ID list entry */
00173 struct isapnp_device_id {
00174         /** Name */
00175         const char *name;
00176         /** Vendor ID */
00177         uint16_t vendor_id;
00178         /** Product ID */
00179         uint16_t prod_id;
00180 };
00181 
00182 /** An ISAPnP device */
00183 struct isapnp_device {
00184         /** Generic device */
00185         struct device dev;
00186         /** Vendor ID */
00187         uint16_t vendor_id;
00188         /** Product ID */
00189         uint16_t prod_id;
00190         /** I/O address */
00191         uint16_t ioaddr;
00192         /** Interrupt number */
00193         uint8_t irqno;
00194         /** Card Select Number */
00195         uint8_t csn;
00196         /** Logical Device ID */
00197         uint8_t logdev;
00198         /** Driver for this device */
00199         struct isapnp_driver *driver;
00200         /** Driver-private data
00201          *
00202          * Use isapnp_set_drvdata() and isapnp_get_drvdata() to access
00203          * this field.
00204          */
00205         void *priv;
00206 };
00207 
00208 /** An ISAPnP driver */
00209 struct isapnp_driver {
00210         /** ISAPnP ID table */
00211         struct isapnp_device_id *ids;
00212         /** Number of entries in ISAPnP ID table */
00213         unsigned int id_count;
00214         /**
00215          * Probe device
00216          *
00217          * @v isapnp    ISAPnP device
00218          * @v id        Matching entry in ID table
00219          * @ret rc      Return status code
00220          */
00221         int ( * probe ) ( struct isapnp_device *isapnp,
00222                           const struct isapnp_device_id *id );
00223         /**
00224          * Remove device
00225          *
00226          * @v isapnp    ISAPnP device
00227          */
00228         void ( * remove ) ( struct isapnp_device *isapnp );
00229 };
00230 
00231 /** ISAPnP driver table */
00232 #define ISAPNP_DRIVERS __table ( struct isapnp_driver, "isapnp_drivers" )
00233 
00234 /** Declare an ISAPnP driver */
00235 #define __isapnp_driver __table_entry ( ISAPNP_DRIVERS, 01 )
00236 
00237 extern uint16_t isapnp_read_port;
00238 
00239 extern void isapnp_device_activation ( struct isapnp_device *isapnp,
00240                                        int activation );
00241 
00242 /**
00243  * Activate ISAPnP device
00244  *
00245  * @v isapnp            ISAPnP device
00246  */
00247 static inline void activate_isapnp_device ( struct isapnp_device *isapnp ) {
00248         isapnp_device_activation ( isapnp, 1 );
00249 }
00250 
00251 /**
00252  * Deactivate ISAPnP device
00253  *
00254  * @v isapnp            ISAPnP device
00255  */
00256 static inline void deactivate_isapnp_device ( struct isapnp_device *isapnp ) {
00257         isapnp_device_activation ( isapnp, 0 );
00258 }
00259 
00260 /**
00261  * Set ISAPnP driver-private data
00262  *
00263  * @v isapnp            ISAPnP device
00264  * @v priv              Private data
00265  */
00266 static inline void isapnp_set_drvdata ( struct isapnp_device *isapnp,
00267                                         void *priv ) {
00268         isapnp->priv = priv;
00269 }
00270 
00271 /**
00272  * Get ISAPnP driver-private data
00273  *
00274  * @v isapnp            ISAPnP device
00275  * @ret priv            Private data
00276  */
00277 static inline void * isapnp_get_drvdata ( struct isapnp_device *isapnp ) {
00278         return isapnp->priv;
00279 }
00280 
00281 #endif /* ISAPNP_H */