Skip to content

Commit

Permalink
dev/hda: Only enumerate paths once for the whole device
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwinci committed Sep 2, 2023
1 parent 7e875c0 commit 7427ee0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/dev/audio/hda/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ typedef struct Widget {
u32 in_amp;
u32 out_amp;
u32 vol_caps;
u32 audio_caps;
u32 conf;
u8 con_list_len;
u8 nid;
Expand Down Expand Up @@ -360,6 +361,7 @@ static void codec_enumerate(Controller* self, u8 num) {
Widget* widget = kmalloc(sizeof(Widget));
assert(widget);

widget->audio_caps = res.response;
widget->pin_caps = hda_send_cmd_await(self, PARAM_PIN_CAPABILITIES, CMD_GET_PARAMETER, nid, num).response;
widget->in_amp = hda_send_cmd_await(self, PARAM_INPUT_AMP_CAPABILITIES, CMD_GET_PARAMETER, nid, num).response;
widget->out_amp = hda_send_cmd_await(self, PARAM_OUTPUT_AMP_CAPABILITIES, CMD_GET_PARAMETER, nid, num).response;
Expand All @@ -373,6 +375,12 @@ static void codec_enumerate(Controller* self, u8 num) {
assert(!widget->con_list_len || widget->con_list);
for (u8 j = 0; j < widget->con_list_len; j += 4) {
u32 con_res = hda_send_cmd_await(self, j, CMD_GET_CONNECTION_LIST_ENTRY, nid, num).response;
if (!con_res) {
kfree(widget->con_list, widget->con_list_len);
widget->con_list = NULL;
widget->con_list_len = 0;
break;
}
for (u8 short_i = 0; short_i < (u8) MIN(widget->con_list_len - j, 4); ++short_i) {
widget->con_list[j + short_i] = con_res >> (short_i * 8) & 0xFF;
}
Expand Down Expand Up @@ -415,8 +423,6 @@ static void codec_enumerate(Controller* self, u8 num) {
widget_nid_tab_insert(&self->nid_tables[num], nid, widget);
}

find_output_paths(self);

/*u16 pin_connected_to_nid = self->pins->con_list[0] & 0x7FFF;
bool range_nids = self->pins->con_list[0] >> 15;
assert(!range_nids);
Expand Down Expand Up @@ -594,7 +600,9 @@ static AudioStream* snd_create_stream(SndDev* snd_self, AudioParams* params) {
Widget* start = path->widgets[0];
assert(start->type == WIDGET_AUDIO_PIN_COMPLEX);
Widget* end = path->widgets[path->len - 1];
assert(end->type == WIDGET_AUDIO_OUT);
if (end->type != WIDGET_AUDIO_OUT) {
continue;
}
if (start->conf) {
u8 location = start->conf >> 24 & 0b111111;

Expand Down Expand Up @@ -635,7 +643,8 @@ static AudioStream* snd_create_stream(SndDev* snd_self, AudioParams* params) {
specific_str = "Unknown";
}

kprintf("%u: %s\n", i, specific_str);
if (specific == 2)
kprintf("%u: %s\n", i, specific_str);
}
else {
kprintf("unknown start\n");
Expand Down Expand Up @@ -984,6 +993,8 @@ static void hda_init(PciDev* dev) {
}
}

find_output_paths(self);

assert(pci_irq_alloc(dev, 0, 0, PCI_IRQ_ALLOC_SHARED | PCI_IRQ_ALLOC_ALL));
u32 irq = pci_irq_get(dev, 0);

Expand Down

0 comments on commit 7427ee0

Please sign in to comment.