blob: de4144c8cc03ece56366b0876a402b89e4fd81b3 [file] [log] [blame]
swissChili5fe85a12021-05-31 08:10:27 -07001#include <alloc.h>
swissChilie5adca52021-06-16 21:00:31 -07002#include <dri/ata_pio/ata_pio.h>
3#include <dri/ide/ide.h>
swissChili1b839222021-06-03 13:54:40 -07004#include <log.h>
swissChilie5adca52021-06-16 21:00:31 -07005#include <task.h>
swissChili5fe85a12021-05-31 08:10:27 -07006
7struct ide_thread_data
8{
swissChilie5adca52021-06-16 21:00:31 -07009 struct pci_device dev;
10 uchar bus, slot, func;
swissChili5fe85a12021-05-31 08:10:27 -070011};
12
13bool ide_supports(struct pci_device *dev)
14{
swissChilie5adca52021-06-16 21:00:31 -070015 return dev->class == 1 && dev->subclass == 1;
swissChili5fe85a12021-05-31 08:10:27 -070016}
17
swissChilief829f32021-06-13 20:00:54 -070018void ide_print_device(struct ide_device *dev)
19{
swissChilie5adca52021-06-16 21:00:31 -070020 kprintf(INFO "<ide-device dma=%b>\n", dev->supports_dma);
swissChilief829f32021-06-13 20:00:54 -070021}
22
swissChili5fe85a12021-05-31 08:10:27 -070023void ide_thread(struct ide_thread_data *data)
24{
swissChilie5adca52021-06-16 21:00:31 -070025 struct ide_device dev;
swissChilief829f32021-06-13 20:00:54 -070026
swissChilie5adca52021-06-16 21:00:31 -070027 uchar p = data->dev.prog_if;
28 dev.channel_mode[0] = p & 1;
29 dev.channel_mode_modifiable[0] = p & (1 << 1);
30 dev.channel_mode[1] = p & (1 << 2);
31 dev.channel_mode_modifiable[1] = p & (1 << 3);
32 dev.supports_dma = p & (1 << 7);
swissChilief829f32021-06-13 20:00:54 -070033
swissChilie5adca52021-06-16 21:00:31 -070034 ide_print_device(&dev);
swissChilief829f32021-06-13 20:00:54 -070035
swissChilie5adca52021-06-16 21:00:31 -070036 // TODO: pass ATA PIO driver information about the IDE device (i.e. what
37 // ports to use)
38 init_ata_pio();
39
40 kprintf(OKAY "Set up ATA PIO\n");
41
42 free(data);
swissChili5fe85a12021-05-31 08:10:27 -070043}
44
45void ide_init(struct pci_device dev, uchar bus, uchar slot, uchar func)
46{
swissChilie5adca52021-06-16 21:00:31 -070047 struct ide_thread_data *data = malloc(sizeof(struct ide_thread_data));
48 data->dev = dev;
49 data->bus = bus;
50 data->slot = slot;
51 data->func = func;
swissChili5fe85a12021-05-31 08:10:27 -070052
swissChilie5adca52021-06-16 21:00:31 -070053 ide_thread(data);
swissChili5fe85a12021-05-31 08:10:27 -070054}
55
56void ide_register()
57{
swissChilie5adca52021-06-16 21:00:31 -070058 struct pci_device_driver dri = {
59 .supports = ide_supports,
60 .init = ide_init,
61 .generic_name = "IDE Controller",
62 };
swissChili5fe85a12021-05-31 08:10:27 -070063
swissChilie5adca52021-06-16 21:00:31 -070064 pci_register_device_driver(dri);
swissChili5fe85a12021-05-31 08:10:27 -070065}