You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bitbash.h 1.9KB

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