1 #ifndef HW_INTEL_HDA_H 2 #define HW_INTEL_HDA_H 3 4 #include "hw/qdev-core.h" 5 #include "qom/object.h" 6 7 /* --------------------------------------------------------------------- */ 8 /* hda bus */ 9 10 #define TYPE_HDA_CODEC_DEVICE "hda-codec" 11 typedef struct HDACodecDevice HDACodecDevice; 12 typedef struct HDACodecDeviceClass HDACodecDeviceClass; 13 #define HDA_CODEC_DEVICE(obj) \ 14 OBJECT_CHECK(HDACodecDevice, (obj), TYPE_HDA_CODEC_DEVICE) 15 #define HDA_CODEC_DEVICE_CLASS(klass) \ 16 OBJECT_CLASS_CHECK(HDACodecDeviceClass, (klass), TYPE_HDA_CODEC_DEVICE) 17 #define HDA_CODEC_DEVICE_GET_CLASS(obj) \ 18 OBJECT_GET_CLASS(HDACodecDeviceClass, (obj), TYPE_HDA_CODEC_DEVICE) 19 20 #define TYPE_HDA_BUS "HDA" 21 typedef struct HDACodecBus HDACodecBus; 22 #define HDA_BUS(obj) OBJECT_CHECK(HDACodecBus, (obj), TYPE_HDA_BUS) 23 24 25 typedef void (*hda_codec_response_func)(HDACodecDevice *dev, 26 bool solicited, uint32_t response); 27 typedef bool (*hda_codec_xfer_func)(HDACodecDevice *dev, 28 uint32_t stnr, bool output, 29 uint8_t *buf, uint32_t len); 30 31 struct HDACodecBus { 32 BusState qbus; 33 uint32_t next_cad; 34 hda_codec_response_func response; 35 hda_codec_xfer_func xfer; 36 }; 37 38 struct HDACodecDeviceClass { 39 DeviceClass parent_class; 40 41 int (*init)(HDACodecDevice *dev); 42 void (*exit)(HDACodecDevice *dev); 43 void (*command)(HDACodecDevice *dev, uint32_t nid, uint32_t data); 44 void (*stream)(HDACodecDevice *dev, uint32_t stnr, bool running, bool output); 45 }; 46 47 struct HDACodecDevice { 48 DeviceState qdev; 49 uint32_t cad; /* codec address */ 50 }; 51 52 void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus, size_t bus_size, 53 hda_codec_response_func response, 54 hda_codec_xfer_func xfer); 55 HDACodecDevice *hda_codec_find(HDACodecBus *bus, uint32_t cad); 56 57 void hda_codec_response(HDACodecDevice *dev, bool solicited, uint32_t response); 58 bool hda_codec_xfer(HDACodecDevice *dev, uint32_t stnr, bool output, 59 uint8_t *buf, uint32_t len); 60 61 /* --------------------------------------------------------------------- */ 62 63 #define dprint(_dev, _level, _fmt, ...) \ 64 do { \ 65 if (_dev->debug >= _level) { \ 66 fprintf(stderr, "%s: ", _dev->name); \ 67 fprintf(stderr, _fmt, ## __VA_ARGS__); \ 68 } \ 69 } while (0) 70 71 /* --------------------------------------------------------------------- */ 72 73 #endif 74