Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / bitbash.h
1 #ifndef _IPXE_BITBASH_H
2 #define _IPXE_BITBASH_H
3
4 /** @file
5  *
6  * Bit-bashing interfaces
7  *
8  */
9
10 FILE_LICENCE ( GPL2_OR_LATER );
11
12 struct bit_basher;
13
14 /** Bit-bashing operations */
15 struct bit_basher_operations {
16         /**
17          * Open bit-bashing interface (optional)
18          *
19          * @v basher            Bit-bashing interface
20          */
21         void ( * open ) ( struct bit_basher *basher );
22         /**
23          * Close bit-bashing interface (optional)
24          *
25          * @v basher            Bit-bashing interface
26          */
27         void ( * close ) ( struct bit_basher *basher );
28         /**
29          * Set/clear output bit
30          *
31          * @v basher            Bit-bashing interface
32          * @v bit_id            Bit number
33          * @v data              Value to write
34          * 
35          * @c data will be 0 if a logic 0 should be written (i.e. the
36          * bit should be cleared), or -1UL if a logic 1 should be
37          * written (i.e. the bit should be set).  This is done so that
38          * the method may simply binary-AND @c data with the
39          * appropriate bit mask.
40          */
41         void ( * write ) ( struct bit_basher *basher, unsigned int bit_id,
42                            unsigned long data );
43         /**
44          * Read input bit
45          *
46          * @v basher            Bit-bashing interface
47          * @v bit_id            Bit number
48          * @ret zero            Input is a logic 0
49          * @ret non-zero        Input is a logic 1
50          */
51         int ( * read ) ( struct bit_basher *basher, unsigned int bit_id );
52 };
53
54 /** A bit-bashing interface */
55 struct bit_basher {
56         /** Bit-bashing operations */
57         struct bit_basher_operations *op;
58 };
59
60 /**
61  * Open bit-bashing interface
62  *
63  * @v basher            Bit-bashing interface
64  */
65 static inline void open_bit ( struct bit_basher *basher ) {
66         if ( basher->op->open )
67                 basher->op->open ( basher );
68 }
69
70 /**
71  * Close bit-bashing interface
72  *
73  * @v basher            Bit-bashing interface
74  */
75 static inline void close_bit ( struct bit_basher *basher ) {
76         if ( basher->op->close )
77                 basher->op->close ( basher );
78 }
79
80 extern void write_bit ( struct bit_basher *basher, unsigned int bit_id,
81                         unsigned long data );
82 extern int read_bit ( struct bit_basher *basher, unsigned int bit_id );
83
84 #endif /* _IPXE_BITBASH_H */