intel-hda.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef HW_INTEL_HDA_H
  2. #define HW_INTEL_HDA_H
  3. #include "hw/qdev-core.h"
  4. #include "qom/object.h"
  5. /* --------------------------------------------------------------------- */
  6. /* hda bus */
  7. #define TYPE_HDA_CODEC_DEVICE "hda-codec"
  8. OBJECT_DECLARE_TYPE(HDACodecDevice, HDACodecDeviceClass,
  9. HDA_CODEC_DEVICE)
  10. #define TYPE_HDA_BUS "HDA"
  11. OBJECT_DECLARE_SIMPLE_TYPE(HDACodecBus, HDA_BUS)
  12. typedef void (*hda_codec_response_func)(HDACodecDevice *dev,
  13. bool solicited, uint32_t response);
  14. typedef bool (*hda_codec_xfer_func)(HDACodecDevice *dev,
  15. uint32_t stnr, bool output,
  16. uint8_t *buf, uint32_t len);
  17. struct HDACodecBus {
  18. BusState qbus;
  19. uint32_t next_cad;
  20. hda_codec_response_func response;
  21. hda_codec_xfer_func xfer;
  22. };
  23. struct HDACodecDeviceClass {
  24. DeviceClass parent_class;
  25. void (*init)(HDACodecDevice *dev, Error **errp);
  26. void (*exit)(HDACodecDevice *dev);
  27. void (*command)(HDACodecDevice *dev, uint32_t nid, uint32_t data);
  28. void (*stream)(HDACodecDevice *dev, uint32_t stnr, bool running, bool output);
  29. };
  30. struct HDACodecDevice {
  31. DeviceState qdev;
  32. uint32_t cad; /* codec address */
  33. };
  34. void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus, size_t bus_size,
  35. hda_codec_response_func response,
  36. hda_codec_xfer_func xfer);
  37. HDACodecDevice *hda_codec_find(HDACodecBus *bus, uint32_t cad);
  38. void hda_codec_response(HDACodecDevice *dev, bool solicited, uint32_t response);
  39. bool hda_codec_xfer(HDACodecDevice *dev, uint32_t stnr, bool output,
  40. uint8_t *buf, uint32_t len);
  41. /* --------------------------------------------------------------------- */
  42. #define dprint(_dev, _level, _fmt, ...) \
  43. do { \
  44. if (_dev->debug >= _level) { \
  45. fprintf(stderr, "%s: ", _dev->name); \
  46. fprintf(stderr, _fmt, ## __VA_ARGS__); \
  47. } \
  48. } while (0)
  49. /* --------------------------------------------------------------------- */
  50. #endif