iPXE
pxe.h
Go to the documentation of this file.
00001 #ifndef PXE_H
00002 #define PXE_H
00003 
00004 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00005 
00006 #include "pxe_types.h"
00007 #include "pxe_error.h"
00008 #include "pxe_api.h"
00009 #include <ipxe/device.h>
00010 #include <ipxe/tables.h>
00011 
00012 /** PXE API invalid function code */
00013 #define PXENV_UNKNOWN 0xffff
00014 
00015 /** Parameter block for pxenv_unknown() */
00016 struct s_PXENV_UNKNOWN {
00017         PXENV_STATUS_t Status;                  /**< PXE status code */
00018 } __attribute__ (( packed ));
00019 
00020 typedef struct s_PXENV_UNKNOWN PXENV_UNKNOWN_t;
00021 
00022 /* Union used for PXE API calls; we don't know the type of the
00023  * structure until we interpret the opcode.  Also, Status is available
00024  * in the same location for any opcode, and it's convenient to have
00025  * non-specific access to it.
00026  */
00027 union u_PXENV_ANY {
00028         /* Make it easy to read status for any operation */
00029         PXENV_STATUS_t                          Status;
00030         struct s_PXENV_UNKNOWN                  unknown;
00031         struct s_PXENV_UNLOAD_STACK             unload_stack;
00032         struct s_PXENV_GET_CACHED_INFO          get_cached_info;
00033         struct s_PXENV_TFTP_READ_FILE           restart_tftp;
00034         struct s_PXENV_START_UNDI               start_undi;
00035         struct s_PXENV_STOP_UNDI                stop_undi;
00036         struct s_PXENV_START_BASE               start_base;
00037         struct s_PXENV_STOP_BASE                stop_base;
00038         struct s_PXENV_TFTP_OPEN                tftp_open;
00039         struct s_PXENV_TFTP_CLOSE               tftp_close;
00040         struct s_PXENV_TFTP_READ                tftp_read;
00041         struct s_PXENV_TFTP_READ_FILE           tftp_read_file;
00042         struct s_PXENV_TFTP_GET_FSIZE           tftp_get_fsize;
00043         struct s_PXENV_UDP_OPEN                 udp_open;
00044         struct s_PXENV_UDP_CLOSE                udp_close;
00045         struct s_PXENV_UDP_WRITE                udp_write;
00046         struct s_PXENV_UDP_READ                 udp_read;
00047         struct s_PXENV_UNDI_STARTUP             undi_startup;
00048         struct s_PXENV_UNDI_CLEANUP             undi_cleanup;
00049         struct s_PXENV_UNDI_INITIALIZE          undi_initialize;
00050         struct s_PXENV_UNDI_RESET               undi_reset_adapter;
00051         struct s_PXENV_UNDI_SHUTDOWN            undi_shutdown;
00052         struct s_PXENV_UNDI_OPEN                undi_open;
00053         struct s_PXENV_UNDI_CLOSE               undi_close;
00054         struct s_PXENV_UNDI_TRANSMIT            undi_transmit;
00055         struct s_PXENV_UNDI_SET_MCAST_ADDRESS   undi_set_mcast_address;
00056         struct s_PXENV_UNDI_SET_STATION_ADDRESS undi_set_station_address;
00057         struct s_PXENV_UNDI_SET_PACKET_FILTER   undi_set_packet_filter;
00058         struct s_PXENV_UNDI_GET_INFORMATION     undi_get_information;
00059         struct s_PXENV_UNDI_GET_STATISTICS      undi_get_statistics;
00060         struct s_PXENV_UNDI_CLEAR_STATISTICS    undi_clear_statistics;
00061         struct s_PXENV_UNDI_INITIATE_DIAGS      undi_initiate_diags;
00062         struct s_PXENV_UNDI_FORCE_INTERRUPT     undi_force_interrupt;
00063         struct s_PXENV_UNDI_GET_MCAST_ADDRESS   undi_get_mcast_address;
00064         struct s_PXENV_UNDI_GET_NIC_TYPE        undi_get_nic_type;
00065         struct s_PXENV_UNDI_GET_IFACE_INFO      undi_get_iface_info;
00066         struct s_PXENV_UNDI_GET_STATE           undi_get_state;
00067         struct s_PXENV_UNDI_ISR                 undi_isr;
00068         struct s_PXENV_FILE_OPEN                file_open;
00069         struct s_PXENV_FILE_CLOSE               file_close;
00070         struct s_PXENV_FILE_SELECT              file_select;
00071         struct s_PXENV_FILE_READ                file_read;
00072         struct s_PXENV_GET_FILE_SIZE            get_file_size;
00073         struct s_PXENV_FILE_EXEC                file_exec;
00074         struct s_PXENV_FILE_API_CHECK           file_api_check;
00075         struct s_PXENV_FILE_EXIT_HOOK           file_exit_hook;
00076 };
00077 
00078 typedef union u_PXENV_ANY PXENV_ANY_t;
00079 
00080 /** A PXE API call */
00081 struct pxe_api_call {
00082         /** Entry point
00083          *
00084          * @v params            PXE API call parameters
00085          * @ret exit            PXE API call exit code
00086          */
00087         PXENV_EXIT_t ( * entry ) ( union u_PXENV_ANY *params );
00088         /** Length of parameters */
00089         uint16_t params_len;
00090         /** Opcode */
00091         uint16_t opcode;
00092 };
00093 
00094 /** PXE API call table */
00095 #define PXE_API_CALLS __table ( struct pxe_api_call, "pxe_api_calls" )
00096 
00097 /** Declare a PXE API call */
00098 #define __pxe_api_call __table_entry ( PXE_API_CALLS, 01 )
00099 
00100 /**
00101  * Define a PXE API call
00102  *
00103  * @v _opcode           Opcode
00104  * @v _entry            Entry point
00105  * @v _params_type      Type of parameter structure
00106  * @ret call            PXE API call
00107  */
00108 #define PXE_API_CALL( _opcode, _entry, _params_type ) {                       \
00109         .entry = ( ( ( ( PXENV_EXIT_t ( * ) ( _params_type *params ) ) NULL ) \
00110                     == ( ( typeof ( _entry ) * ) NULL ) )                     \
00111                    ? ( ( PXENV_EXIT_t ( * )                                   \
00112                          ( union u_PXENV_ANY *params ) ) _entry )             \
00113                    : ( ( PXENV_EXIT_t ( * )                                   \
00114                          ( union u_PXENV_ANY *params ) ) _entry ) ),          \
00115         .params_len = sizeof ( _params_type ),                                \
00116         .opcode = _opcode,                                                    \
00117         }
00118 
00119 /** An UNDI expansion ROM header */
00120 struct undi_rom_header {
00121         /** Signature
00122          *
00123          * Must be equal to @c ROM_SIGNATURE
00124          */
00125         UINT16_t Signature;
00126         /** ROM length in 512-byte blocks */
00127         UINT8_t ROMLength;
00128         /** Unused */
00129         UINT8_t unused[0x13];
00130         /** Offset of the PXE ROM ID structure */
00131         UINT16_t PXEROMID;
00132         /** Offset of the PCI ROM structure */
00133         UINT16_t PCIRHeader;
00134 } __attribute__ (( packed ));
00135 
00136 /** Signature for an expansion ROM */
00137 #define ROM_SIGNATURE 0xaa55
00138 
00139 /** An UNDI ROM ID structure */
00140 struct undi_rom_id {
00141         /** Signature
00142          *
00143          * Must be equal to @c UNDI_ROM_ID_SIGNATURE
00144          */
00145         UINT32_t Signature;
00146         /** Length of structure */
00147         UINT8_t StructLength;
00148         /** Checksum */
00149         UINT8_t StructCksum;
00150         /** Structure revision
00151          *
00152          * Must be zero.
00153          */
00154         UINT8_t StructRev;
00155         /** UNDI revision
00156          *
00157          * Version 2.1.0 is encoded as the byte sequence 0x00, 0x01, 0x02.
00158          */
00159         UINT8_t UNDIRev[3];
00160         /** Offset to UNDI loader */
00161         UINT16_t UNDILoader;
00162         /** Minimum required stack segment size */
00163         UINT16_t StackSize;
00164         /** Minimum required data segment size */
00165         UINT16_t DataSize;
00166         /** Minimum required code segment size */
00167         UINT16_t CodeSize;
00168 } __attribute__ (( packed ));
00169 
00170 /** Signature for an UNDI ROM ID structure */
00171 #define UNDI_ROM_ID_SIGNATURE \
00172         ( ( 'U' << 0 ) + ( 'N' << 8 ) + ( 'D' << 16 ) + ( 'I' << 24 ) )
00173 
00174 /** A PCI expansion header */
00175 struct pcir_header {
00176         /** Signature
00177          *
00178          * Must be equal to @c PCIR_SIGNATURE
00179          */
00180         uint32_t signature;
00181         /** PCI vendor ID */
00182         uint16_t vendor_id;
00183         /** PCI device ID */
00184         uint16_t device_id;
00185 } __attribute__ (( packed ));
00186 
00187 /** Signature for an UNDI ROM ID structure */
00188 #define PCIR_SIGNATURE \
00189         ( ( 'P' << 0 ) + ( 'C' << 8 ) + ( 'I' << 16 ) + ( 'R' << 24 ) )
00190 
00191 extern struct net_device *pxe_netdev;
00192 extern const char *pxe_cmdline;
00193 
00194 extern void pxe_set_netdev ( struct net_device *netdev );
00195 extern void pxe_fake_cached_info ( void );
00196 extern PXENV_EXIT_t pxenv_tftp_read_file ( struct s_PXENV_TFTP_READ_FILE
00197                                            *tftp_read_file );
00198 extern PXENV_EXIT_t undi_loader ( struct s_UNDI_LOADER *undi_loader );
00199 
00200 #endif /* PXE_H */