iPXE
bitbash.h
Go to the documentation of this file.
00001 #ifndef _IPXE_BITBASH_H
00002 #define _IPXE_BITBASH_H
00003 
00004 /** @file
00005  *
00006  * Bit-bashing interfaces
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 struct bit_basher;
00013 
00014 /** Bit-bashing operations */
00015 struct bit_basher_operations {
00016         /**
00017          * Open bit-bashing interface (optional)
00018          *
00019          * @v basher            Bit-bashing interface
00020          */
00021         void ( * open ) ( struct bit_basher *basher );
00022         /**
00023          * Close bit-bashing interface (optional)
00024          *
00025          * @v basher            Bit-bashing interface
00026          */
00027         void ( * close ) ( struct bit_basher *basher );
00028         /**
00029          * Set/clear output bit
00030          *
00031          * @v basher            Bit-bashing interface
00032          * @v bit_id            Bit number
00033          * @v data              Value to write
00034          * 
00035          * @c data will be 0 if a logic 0 should be written (i.e. the
00036          * bit should be cleared), or -1UL if a logic 1 should be
00037          * written (i.e. the bit should be set).  This is done so that
00038          * the method may simply binary-AND @c data with the
00039          * appropriate bit mask.
00040          */
00041         void ( * write ) ( struct bit_basher *basher, unsigned int bit_id,
00042                            unsigned long data );
00043         /**
00044          * Read input bit
00045          *
00046          * @v basher            Bit-bashing interface
00047          * @v bit_id            Bit number
00048          * @ret zero            Input is a logic 0
00049          * @ret non-zero        Input is a logic 1
00050          */
00051         int ( * read ) ( struct bit_basher *basher, unsigned int bit_id );
00052 };
00053 
00054 /** A bit-bashing interface */
00055 struct bit_basher {
00056         /** Bit-bashing operations */
00057         struct bit_basher_operations *op;
00058 };
00059 
00060 /**
00061  * Open bit-bashing interface
00062  *
00063  * @v basher            Bit-bashing interface
00064  */
00065 static inline void open_bit ( struct bit_basher *basher ) {
00066         if ( basher->op->open )
00067                 basher->op->open ( basher );
00068 }
00069 
00070 /**
00071  * Close bit-bashing interface
00072  *
00073  * @v basher            Bit-bashing interface
00074  */
00075 static inline void close_bit ( struct bit_basher *basher ) {
00076         if ( basher->op->close )
00077                 basher->op->close ( basher );
00078 }
00079 
00080 extern void write_bit ( struct bit_basher *basher, unsigned int bit_id,
00081                         unsigned long data );
00082 extern int read_bit ( struct bit_basher *basher, unsigned int bit_id );
00083 
00084 #endif /* _IPXE_BITBASH_H */