swissChili | 5fe85a1 | 2021-05-31 08:10:27 -0700 | [diff] [blame] | 1 | #include <dri/ide/ide.h> |
| 2 | #include <task.h> |
| 3 | #include <alloc.h> |
swissChili | 1b83922 | 2021-06-03 13:54:40 -0700 | [diff] [blame] | 4 | #include <log.h> |
swissChili | 5fe85a1 | 2021-05-31 08:10:27 -0700 | [diff] [blame] | 5 | |
| 6 | struct ide_thread_data |
| 7 | { |
| 8 | struct pci_device dev; |
| 9 | uchar bus, slot, func; |
| 10 | }; |
| 11 | |
| 12 | bool ide_supports(struct pci_device *dev) |
| 13 | { |
| 14 | return dev->class == 1 && dev->subclass == 1; |
| 15 | } |
| 16 | |
swissChili | ef829f3 | 2021-06-13 20:00:54 -0700 | [diff] [blame] | 17 | void ide_print_device(struct ide_device *dev) |
| 18 | { |
| 19 | kprintf("<ide-device dma=%b>", dev->supports_dma); |
| 20 | } |
| 21 | |
swissChili | 5fe85a1 | 2021-05-31 08:10:27 -0700 | [diff] [blame] | 22 | void ide_thread(struct ide_thread_data *data) |
| 23 | { |
| 24 | kprintf("IDE driver thread starting: device=0x%x\n", data->dev.device_id); |
swissChili | ef829f3 | 2021-06-13 20:00:54 -0700 | [diff] [blame] | 25 | |
| 26 | struct ide_device dev; |
| 27 | |
| 28 | uchar p = data->dev.prog_if; |
| 29 | dev.channel_mode[0] = p & 1; |
| 30 | dev.channel_mode_modifiable[0] = p & (1 << 1); |
| 31 | dev.channel_mode[1] = p & (1 << 2); |
| 32 | dev.channel_mode_modifiable[1] = p & (1 << 3); |
| 33 | dev.supports_dma = p & (1 << 7); |
| 34 | |
| 35 | ide_print_device(&dev); |
swissChili | 5fe85a1 | 2021-05-31 08:10:27 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void ide_init(struct pci_device dev, uchar bus, uchar slot, uchar func) |
| 39 | { |
| 40 | struct ide_thread_data *data = malloc(sizeof(struct ide_thread_data)); |
| 41 | data->dev = dev; |
| 42 | data->bus = bus; |
| 43 | data->slot = slot; |
| 44 | data->func = func; |
| 45 | |
swissChili | 1b83922 | 2021-06-03 13:54:40 -0700 | [diff] [blame] | 46 | spawn_thread(TASK_FUNCTION(ide_thread), data); |
swissChili | 5fe85a1 | 2021-05-31 08:10:27 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void ide_register() |
| 50 | { |
| 51 | struct pci_device_driver dri = |
| 52 | { |
| 53 | .supports = ide_supports, |
| 54 | .init = ide_init, |
| 55 | .generic_name = "IDE Controller", |
| 56 | }; |
| 57 | |
| 58 | pci_register_device_driver(dri); |
| 59 | } |