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 OBJECT_DECLARE_TYPE(HDACodecDevice, HDACodecDeviceClass, 12 hda_codec_device, HDA_CODEC_DEVICE) 13 14 #define TYPE_HDA_BUS "HDA" 15 typedef struct HDACodecBus HDACodecBus; 16 DECLARE_INSTANCE_CHECKER(HDACodecBus, HDA_BUS, 17 TYPE_HDA_BUS) 18 19 20 typedef void (*hda_codec_response_func)(HDACodecDevice *dev, 21 bool solicited, uint32_t response); 22 typedef bool (*hda_codec_xfer_func)(HDACodecDevice *dev, 23 uint32_t stnr, bool output, 24 uint8_t *buf, uint32_t len); 25 26 struct HDACodecBus { 27 BusState qbus; 28 uint32_t next_cad; 29 hda_codec_response_func response; 30 hda_codec_xfer_func xfer; 31 }; 32 33 struct HDACodecDeviceClass { 34 DeviceClass parent_class; 35 36 int (*init)(HDACodecDevice *dev); 37 void (*exit)(HDACodecDevice *dev); 38 void (*command)(HDACodecDevice *dev, uint32_t nid, uint32_t data); 39 void (*stream)(HDACodecDevice *dev, uint32_t stnr, bool running, bool output); 40 }; 41 42 struct HDACodecDevice { 43 DeviceState qdev; 44 uint32_t cad; /* codec address */ 45 }; 46 47 void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus, size_t bus_size, 48 hda_codec_response_func response, 49 hda_codec_xfer_func xfer); 50 HDACodecDevice *hda_codec_find(HDACodecBus *bus, uint32_t cad); 51 52 void hda_codec_response(HDACodecDevice *dev, bool solicited, uint32_t response); 53 bool hda_codec_xfer(HDACodecDevice *dev, uint32_t stnr, bool output, 54 uint8_t *buf, uint32_t len); 55 56 /* --------------------------------------------------------------------- */ 57 58 #define dprint(_dev, _level, _fmt, ...) \ 59 do { \ 60 if (_dev->debug >= _level) { \ 61 fprintf(stderr, "%s: ", _dev->name); \ 62 fprintf(stderr, _fmt, ## __VA_ARGS__); \ 63 } \ 64 } while (0) 65 66 /* --------------------------------------------------------------------- */ 67 68 #endif 69