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