blob: 0025970a3b1f105de6a47bca8b1ee373fabe2d19 [file] [log] [blame]
swissChili5fe85a12021-05-31 08:10:27 -07001#include <dri/ide/ide.h>
2#include <task.h>
3#include <alloc.h>
swissChili1b839222021-06-03 13:54:40 -07004#include <log.h>
swissChili5fe85a12021-05-31 08:10:27 -07005
6struct ide_thread_data
7{
8 struct pci_device dev;
9 uchar bus, slot, func;
10};
11
12bool ide_supports(struct pci_device *dev)
13{
14 return dev->class == 1 && dev->subclass == 1;
15}
16
swissChilief829f32021-06-13 20:00:54 -070017void ide_print_device(struct ide_device *dev)
18{
swissChili9bd74de2021-06-15 20:30:48 -070019 kprintf(INFO "<ide-device dma=%b>", dev->supports_dma);
swissChilief829f32021-06-13 20:00:54 -070020}
21
swissChili5fe85a12021-05-31 08:10:27 -070022void ide_thread(struct ide_thread_data *data)
23{
swissChili9bd74de2021-06-15 20:30:48 -070024 kprintf(DEBUG "IDE driver thread starting: device=0x%x\n", data->dev.device_id);
swissChilief829f32021-06-13 20:00:54 -070025
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);
swissChili5fe85a12021-05-31 08:10:27 -070036}
37
38void 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
swissChili1b839222021-06-03 13:54:40 -070046 spawn_thread(TASK_FUNCTION(ide_thread), data);
swissChili5fe85a12021-05-31 08:10:27 -070047}
48
49void 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}