AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
ata.c
Go to the documentation of this file.
1
13
14#include <core/system.h>
15#include <core/module.h>
16#include <core/kargs.h>
17
18#include <cpu/io.h>
19#include <dev/dev.h>
20#include <fs/vfs.h>
21#include <fs/devfs.h>
22#include <fs/posix.h>
23#include <fs/mbr.h>
24#include <aquila/errno.h>
25
26#include <dev/pci.h>
27#include <dev/blkcache.h>
28#include <dev/irq.h>
29#include <sys/sched.h>
30
31#include <ata.h>
32
33#define BLOCK_SIZE 512UL
34
35static struct ata_drive drives[4];
36static struct ata_channel channels[2];
37
41static void channel_acquire(struct ata_channel *ch)
42{
43 while (ch->busy && sched_running && curthread)
45
46 ch->busy = 1;
47}
48
50static void channel_release(struct ata_channel *ch)
51{
52 ch->busy = 0;
54}
55
58static ssize_t drive_read(void *_drive, uint64_t lba, size_t count, void *buf)
59{
60 struct ata_drive *drive = _drive;
61
63 ssize_t ret = drive->read(drive, lba, count, buf);
65
66 return ret;
67}
68
70static ssize_t drive_write(void *_drive, uint64_t lba, size_t count, void *buf)
71{
72 struct ata_drive *drive = _drive;
73
75 ssize_t ret = drive->write(drive, lba, count, buf);
77
78 return ret;
79}
80
82static void ata_irq(void *channel)
83{
85}
86
87/* the drive and mode last written to the drive select register, so that
88 * selecting the same again is skipped; a reset forgets them */
91
97void ata_reset(struct ata_drive *drive)
98{
99 /* select the master first, so that the status is its (an absent slave
100 * would read 0, which hides BSY) */
101 io_out8(&drive->base, ATA_REG_HDDEVSEL, 0xA0);
102 ata_wait(drive);
103
104 io_out8(&drive->ctrl, 0, ATA_CMD_RESET);
105 ata_wait(drive);
106 io_out8(&drive->ctrl, 0, 0);
107 ata_wait(drive);
108
109 for (int i = 0; i < ATA_TIMEOUT; ++i) {
110 if (!(io_in8(&drive->ctrl, 0) & ATA_STATUS_BSY))
111 break;
112 }
113
114 /* a reset changes the drive selection: the next select must happen */
117}
118
127{
128 if (drive != last_selected_drive || mode != last_selected_mode) {
129 if (mode & ATA_MODE_LBA48)
130 io_out8(&drive->base, ATA_REG_HDDEVSEL, 0xE0 | (drive->slave << 4) | (mode & 0xF));
131 else if (mode & ATA_MODE_LBA28)
132 io_out8(&drive->base, ATA_REG_HDDEVSEL, 0xE0 | (drive->slave << 4));
133 else
134 io_out8(&drive->base, ATA_REG_HDDEVSEL, 0xA0 | (drive->slave << 4) | (mode & 0xF));
135
136 ata_wait(drive);
137 ata_wait(drive);
138 ata_wait(drive);
139 ata_wait(drive);
140 ata_wait(drive);
141
142 last_selected_drive = drive;
144 }
145}
146
155void ata_setup(struct ata_drive *drive, uint64_t lba, size_t count)
156{
157 ata_select_drive(drive, drive->mode);
158
159 /* the features register (the error register's port) is 0 */
160 io_out8(&drive->base, ATA_REG_ERROR, 0);
161
162 /* the sector count and the address: with LBA48, the high bytes first,
163 * then the low ones, through the same registers */
164 if (drive->mode == ATA_MODE_LBA48) {
165 io_out8(&drive->base, ATA_REG_SECCOUNT0, (count >> 8) & 0xFF);
166 io_out8(&drive->base, ATA_REG_LBA0, (uint8_t) (lba >> (8 * 3)));
167 io_out8(&drive->base, ATA_REG_LBA1, (uint8_t) (lba >> (8 * 4)));
168 io_out8(&drive->base, ATA_REG_LBA2, (uint8_t) (lba >> (8 * 5)));
169 } else {
170 /* LBA28 has bits 24 to 27 of the address in the drive select
171 * register */
173 0xE0 | (drive->slave << 4) | ((lba >> 24) & 0xF));
174 }
175
176 io_out8(&drive->base, ATA_REG_SECCOUNT0, count & 0xFF);
177 io_out8(&drive->base, ATA_REG_LBA0, (uint8_t) (lba >> (8 * 0)));
178 io_out8(&drive->base, ATA_REG_LBA1, (uint8_t) (lba >> (8 * 1)));
179 io_out8(&drive->base, ATA_REG_LBA2, (uint8_t) (lba >> (8 * 2)));
180}
181
192static int ata_partition(struct ata_drive *drive, size_t part, uint64_t *start, uint64_t *nsectors)
193{
194 if (!part) {
195 *start = 0;
196 *nsectors = drive->max_lba;
197 return 0;
198 }
199
200 part -= 1;
201
202 if (!drive->psize[part]) {
203 char *buf = kmalloc(BLOCK_SIZE, &M_BUFFER, 0);
204
205 if (!buf)
206 return -ENOMEM;
207
208 if (drive->read(drive, 0, 1, buf) < 0) {
209 kfree(buf);
210 return -EIO;
211 }
212
213 struct mbr *mbr = (struct mbr *) buf;
214 struct mbr_part *e = &mbr->ptab[part];
215
216 /* the CHS fields aren't used: every disk since the 90s has the
217 * LBA ones */
218 int found = mbr->boot_signature == 0xAA55 && e->type && e->sectors_count &&
219 (uint64_t) e->start_lba + e->sectors_count <= drive->max_lba;
220
221 if (found) {
222 drive->poff[part] = e->start_lba;
223 drive->psize[part] = e->sectors_count;
224 }
225
226 kfree(buf);
227
228 if (!found)
229 return -ENXIO;
230 }
231
232 *start = drive->poff[part];
233 *nsectors = drive->psize[part];
234 return 0;
235}
236
240static int ata_locate(struct devid *dd, int write, struct ata_drive **ref,
241 uint64_t *start, uint64_t *nsectors)
242{
243 /* 64 minors per drive: the drive's number, then the partition's */
244 size_t drive_id = dd->minor / 64;
245 size_t partition = dd->minor % 64;
246
247 if (drive_id >= 4 || partition > 4)
248 return -ENXIO;
249
250 struct ata_drive *drive = &drives[drive_id];
251
252 if (!(write ? drive->write : drive->read))
253 return -ENXIO;
254
255 channel_acquire(drive->channel);
256 int err = ata_partition(drive, partition, start, nsectors);
257 channel_release(drive->channel);
258
259 *ref = drive;
260 return err;
261}
262
266static ssize_t ata_read(struct devid *dd, off_t offset, size_t size, void *buf)
267{
268 struct ata_drive *drive;
269 uint64_t start, nsectors;
270 int err;
271
272 if ((err = ata_locate(dd, 0, &drive, &start, &nsectors)))
273 return err;
274
275 if ((uint64_t) offset >= nsectors)
276 return 0;
277
278 size = MIN(size, nsectors - offset);
279 err = blkcache_read(drive, start + offset, size, buf, drive->max_lba, drive_read);
280
281 return err < 0 ? err : (ssize_t) size;
282}
283
287static ssize_t ata_write(struct devid *dd, off_t offset, size_t size, void *buf)
288{
289 struct ata_drive *drive;
290 uint64_t start, nsectors;
291 int err;
292
293 if ((err = ata_locate(dd, 1, &drive, &start, &nsectors)))
294 return err;
295
296 if ((uint64_t) offset >= nsectors)
297 return size ? -ENOSPC : 0;
298
299 size = MIN(size, nsectors - offset);
300 err = blkcache_write(drive, start + offset, size, buf, drive_write);
301
302 return err < 0 ? err : (ssize_t) size;
303}
304
308static int ata_drive_present(struct ata_drive *drive)
309{
310 uint8_t status = io_in8(&drive->base, ATA_REG_STATUS);
311
312 if (status == 0xFF || status & ATA_STATUS_BSY)
313 return 0;
314
315 /* an ATA drive says it is ready; an ATAPI drive doesn't, but sets a
316 * signature */
317 if (status & ATA_STATUS_DRDY)
318 return 1;
319
320 uint8_t lba1 = io_in8(&drive->base, ATA_REG_LBA1);
321 uint8_t lba2 = io_in8(&drive->base, ATA_REG_LBA2);
322
323 return (lba1 == 0x14 && lba2 == 0xEB) || (lba1 == 0x69 && lba2 == 0x96);
324}
325
328static uint8_t ata_detect_drive(struct ata_drive *drive)
329{
330 if (!drive->slave) {
331 /* reset both drives on the channel, once */
332 ata_reset(drive);
333 }
334
335 ata_select_drive(drive, 0);
336
337 if (!ata_drive_present(drive)) {
338 /* no drive there */
339 drive->type = ATADEV_NOTFOUND;
340 goto done;
341 }
342
343 uint8_t type_lo = io_in8(&drive->base, ATA_REG_LBA1);
344 uint8_t type_hi = io_in8(&drive->base, ATA_REG_LBA2);
345 uint16_t type = (type_hi << 8) | type_lo;
346
347 switch (type) {
348 case 0x0000:
350 break;
351 case 0xC33C:
353 break;
354 case 0xEB14:
356 break;
357 case 0x9669:
359 break;
360 default:
362 break;
363 }
364
365 if (type == ATADEV_UNKNOWN) {
366 return ATADEV_UNKNOWN;
367 }
368
369 drive->type = type;
370
371 uint8_t identify_command = 0;
372
373 if (type == ATADEV_PATAPI || type == ATADEV_SATAPI) {
374 identify_command = ATA_CMD_IDENTIFY_PACKET;
375 } else {
376 identify_command = ATA_CMD_IDENTIFY;
377 }
378
379 char ide_ident[512];
380 memset(ide_ident, 0, sizeof(ide_ident));
381
382 io_out8(&drive->base, ATA_REG_CMD, identify_command);
383
384 if (io_in8(&drive->base, ATA_REG_STATUS) == 0 || ata_poll(drive, 1)) {
385 /* the drive didn't answer IDENTIFY */
386 drive->type = ATADEV_NOTFOUND;
387 goto done;
388 }
389
390 for (int i = 0; i < 512; i += 2) {
391 uint16_t x = io_in16(&drive->base, ATA_REG_DATA);
392 ide_ident[i+0] = x & 0xFFFF;
393 ide_ident[i+1] = (x >> 8) & 0xFFFF;
394 }
395
396 drive->signature = *(uint16_t *) (ide_ident + ATA_IDENT_DEVICETYPE);
397 drive->capabilities = *(uint16_t *) (ide_ident + ATA_IDENT_CAPABILITIES);
398 drive->command_sets = *(uint32_t *) (ide_ident + ATA_IDENT_COMMANDSETS);
399
400 if (drive->command_sets & (1 << 26)) {
401 /* 48-bit LBA */
402 drive->max_lba = *(uint64_t *) (ide_ident + ATA_IDENT_MAX_LBA_EXT);
403 drive->mode = ATA_MODE_LBA48;
404 } else {
405 /* 28-bit LBA */
406 drive->max_lba = *(uint32_t *) (ide_ident + ATA_IDENT_MAX_LBA);
407 drive->mode = ATA_MODE_LBA28;
408 }
409
410 for (int i = 0; i < 40; i += 2) {
411 drive->model[i + 0] = ide_ident[ATA_IDENT_MODEL + i + 1];
412 drive->model[i + 1] = ide_ident[ATA_IDENT_MODEL + i + 0];
413 }
414 drive->model[40] = 0;
415
416 printk("ata%d: signature: 0x%x\n", drive->id, drive->signature);
417 printk("ata%d: capabilities: 0x%x\n", drive->id, drive->capabilities);
418 printk("ata%d: command Sets: 0x%x\n", drive->id, drive->command_sets);
419 printk("ata%d: max LBA: 0x%lx\n", drive->id, drive->max_lba);
420 printk("ata%d: model: %s\n", drive->id, drive->model);
421
422done:
423 return drive->type;
424}
425
428static int ata_sync(void)
429{
430 int err = 0;
431
432 for (int i = 0; i < 4; ++i) {
433 if (!drives[i].flush)
434 continue;
435
437 if (drives[i].flush(&drives[i]))
438 err = -EIO;
440 }
441
442 return err;
443}
444
446static size_t ata_getbs(struct devid *dd __unused)
447{
448 return BLOCK_SIZE;
449}
450
453static int ata_probe()
454{
455 struct pci_dev ide;
456 int count;
457
458 printk("ata: scanning PCI bus for IDE controller(s)\n");
459
460 count = pci_scan_device(0x01, 0x01, &ide, 1);
461
462 if (!count) {
463 printk("ata: no IDE controller(s) found\n");
464 return -ENODEV;
465 }
466
467 if (count) {
468 printk("ata: found IDE controller: bus: 0x%x, dev: 0x%x, func: 0x%x\n", ide.bus, ide.dev, ide.func);
469
470 uint32_t base, control;
471
472 /* the primary channel: its ports from BARs 0 and 1, or the ISA's
473 * in compatibility mode */
474 base = pci_read_bar(&ide, 0);
475 control = pci_read_bar(&ide, 1);
476
477 if (base == 0 || base == 1)
479
480 if (control == 0 || control == 1)
481 control = ATA_PIO_PRI_PORT_CONTROL;
482
483 printk("ata: IDE controller primary channel: base: 0x%x, control: 0x%x\n", base, control);
484
485 /* in native PCI mode, the channels use the controller's interrupt;
486 * in compatibility mode, the ISA's IRQs 14 and 15 */
487 int native = !(base == ATA_PIO_PRI_PORT_BASE);
488 channels[0].base = (struct ioaddr) {.addr = base, .type = IOADDR_PORT};
489 channels[0].irq = native ? pci_irq(&ide) : 14;
490
491 /* its master drive */
492 drives[0].id = 0;
493 drives[0].base.addr = base;
495 drives[0].ctrl.addr = control;
497 drives[0].slave = 0;
498
499 /* its slave drive */
500 drives[1].id = 1;
501 drives[1].base.addr = base;
503 drives[1].ctrl.addr = control;
505 drives[1].slave = 1;
506
507 /* the secondary channel: BARs 2 and 3 */
508 base = pci_read_bar(&ide, 2);
509 control = pci_read_bar(&ide, 3);
510
511 if (base == 0 || base == 1)
513
514 if (control == 0 || control == 1)
515 control = ATA_PIO_SEC_PORT_CONTROL;
516
517 printk("ata: IDE controller secondary channel: base: 0x%x, control: 0x%x\n", base, control);
518
519 channels[1].base = (struct ioaddr) {.addr = base, .type = IOADDR_PORT};
520 channels[1].irq = native ? channels[0].irq : 15;
521
522 /* the bus master's registers (BAR 4), 8 for each channel */
523 uint32_t bm = pci_read_bar(&ide, 4);
524
525 if ((bm & 1) && (bm & ~3U)) {
526 channels[0].bm = (struct ioaddr) {.addr = bm & ~3U, .type = IOADDR_PORT};
527 channels[1].bm = (struct ioaddr) {.addr = (bm & ~3U) + 8, .type = IOADDR_PORT};
528
529 /* the controller may master the bus */
530 pci_reg16_write(&ide, 0x04, pci_reg16_read(&ide, 0x04) | 0x04);
531
532 printk("ata: bus master DMA at 0x%x\n", bm & ~3U);
533 }
534
535 for (int i = 0; i < 4; ++i)
536 drives[i].channel = &channels[i / 2];
537
538 /* the secondary's master drive */
539 drives[2].id = 2;
540 drives[2].base.addr = base;
542 drives[2].ctrl.addr = control;
544 drives[2].slave = 0;
545
546 /* the secondary's slave drive */
547 drives[3].id = 3;
548 drives[3].base.addr = base;
550 drives[3].ctrl.addr = control;
552 drives[3].slave = 1;
553 }
554
555 for (int i = 0; i < 4 * count; ++i) {
556 uint8_t type = ata_detect_drive(&drives[i]);
557
558 switch (type) {
559 case ATADEV_PATA:
560 pio_init(&drives[i]);
561 /* DMA if possible, unless the ata.nodma argument says PIO */
562 printk("ata%d: initializing ATA device (%s)\n", i,
563 !kargs_get("ata.nodma", NULL) || dma_init(&drives[i]) ? "PIO" : "DMA");
564 break;
565 case ATADEV_SATA:
566 printk("ata%d: SATA is not supported\n", i);
567 break;
568 case ATADEV_PATAPI:
569 printk("ata%d: PATAPI is not supported\n", i);
570 break;
571 case ATADEV_SATAPI:
572 printk("ata%d: SATAPI is not supported\n", i);
573 break;
574 case ATADEV_NOTFOUND:
575 break;
576 default:
577 break;
578 }
579 }
580
581 /* the channels' interrupts: they end DMA transfers, and the others
582 * are acknowledged */
583 if (count) {
584 irq_install(channels[0].irq, ata_irq, &channels[0]);
585 irq_install(channels[1].irq, ata_irq, &channels[1]);
586 }
587
589 return 0;
590}
591
592struct dev atadev = {
593 .name = "ata",
594 .probe = ata_probe,
595 .bread = ata_read,
596 .bwrite = ata_write,
597 .getbs = ata_getbs,
598 .sync = ata_sync,
599
600 .fops = {
601 .open = posix_file_open,
602 .read = posix_file_read,
603 .write = posix_file_write,
604 },
605};
606
int irq_install(unsigned irq, irq_handler_t fn, void *arg)
Installs a handler for an IRQ.
Definition irq.c:32
static uint16_t io_in16(struct ioaddr *io, uintptr_t off)
Definition io.h:33
static uint8_t io_in8(struct ioaddr *io, uintptr_t off)
Reads an 8-, 16- or 32-bit register.
Definition io.h:28
static void io_out8(struct ioaddr *io, uintptr_t off, uint8_t val)
Writes an 8-, 16- or 32-bit register.
Definition io.h:44
#define IOADDR_PORT
Definition io.h:89
void ata_select_drive(struct ata_drive *drive, uint32_t mode)
Selects a drive on its channel, for an addressing mode, if it isn't selected so already,...
Definition ata.c:126
static void channel_acquire(struct ata_channel *ch)
Takes a channel for one command, waiting while another runs (a DMA request sleeps).
Definition ata.c:41
struct dev atadev
Definition ata.c:592
static size_t ata_getbs(struct devid *dd)
Returns the block size: one sector, 512 bytes.
Definition ata.c:446
static uint32_t last_selected_mode
Definition ata.c:90
static struct ata_drive * last_selected_drive
Definition ata.c:89
static struct ata_channel channels[2]
Definition ata.c:36
void ata_setup(struct ata_drive *drive, uint64_t lba, size_t count)
Writes the registers of a command on count sectors from lba: the drive, the address and the count.
Definition ata.c:155
static void channel_release(struct ata_channel *ch)
Gives a channel back, and wakes up the requests waiting for it.
Definition ata.c:50
static ssize_t ata_read(struct devid *dd, off_t offset, size_t size, void *buf)
Reads sectors of a partition, from sector offset on, through the block cache.
Definition ata.c:266
static int ata_partition(struct ata_drive *drive, size_t part, uint64_t *start, uint64_t *nsectors)
Finds partition part of a drive (1 to 4; 0 is the whole disk): its first sector and how many sectors ...
Definition ata.c:192
static void ata_irq(void *channel)
Handles a channel's interrupt.
Definition ata.c:82
static struct ata_drive drives[4]
Definition ata.c:35
static int ata_probe()
Finds the IDE controller, detects its drives, sets them up, and registers the disks as block device 3...
Definition ata.c:453
static uint8_t ata_detect_drive(struct ata_drive *drive)
Detects what a drive is (ATADEV_*).
Definition ata.c:328
void ata_reset(struct ata_drive *drive)
Resets both drives on a drive's channel, and waits until they are done.
Definition ata.c:97
static ssize_t drive_read(void *_drive, uint64_t lba, size_t count, void *buf)
Reads sectors from a drive, for the block cache: the channel is held for the command only,...
Definition ata.c:58
#define BLOCK_SIZE
Definition ata.c:33
static int ata_locate(struct devid *dd, int write, struct ata_drive **ref, uint64_t *start, uint64_t *nsectors)
Finds the drive of a device number, and where its partition is on it.
Definition ata.c:240
static ssize_t drive_write(void *_drive, uint64_t lba, size_t count, void *buf)
Writes sectors to a drive, for the block cache.
Definition ata.c:70
static int ata_sync(void)
Has every drive write what its cache holds to the disk, for sync().
Definition ata.c:428
static ssize_t ata_write(struct devid *dd, off_t offset, size_t size, void *buf)
Writes sectors of a partition, from sector offset on, through the block cache.
Definition ata.c:287
static int ata_drive_present(struct ata_drive *drive)
Returns whether the selected drive is there.
Definition ata.c:308
void dma_irq(struct ata_channel *channel)
Handles a channel's interrupt.
Definition dma.c:76
#define ATA_PIO_SEC_PORT_BASE
Definition ata.h:21
void pio_init(struct ata_drive *drive)
Sets a drive up for PIO, and resets its channel.
Definition pio.c:182
#define ATA_CMD_RESET
Definition ata.h:44
#define ATA_REG_DATA
Definition ata.h:25
#define ATA_REG_STATUS
Definition ata.h:34
#define ATA_STATUS_DRDY
Definition ata.h:63
#define ATA_IDENT_DEVICETYPE
Definition ata.h:82
#define ATA_PIO_PRI_PORT_CONTROL
Definition ata.h:20
#define ATA_REG_LBA1
Definition ata.h:30
#define ATA_IDENT_CAPABILITIES
Definition ata.h:88
#define ATA_PIO_SEC_PORT_CONTROL
Definition ata.h:22
#define ATA_CMD_IDENTIFY
Definition ata.h:57
#define ATA_MODE_LBA28
Definition ata.h:100
#define ATA_TIMEOUT
Definition ata.h:180
#define ATADEV_NOTFOUND
Definition ata.h:12
#define ATA_IDENT_COMMANDSETS
Definition ata.h:91
#define ATA_MODE_LBA48
Definition ata.h:101
#define ATA_REG_LBA0
Definition ata.h:29
#define ATADEV_SATA
Definition ata.h:14
#define ATA_IDENT_MODEL
Definition ata.h:87
#define ATA_IDENT_MAX_LBA_EXT
Definition ata.h:92
#define ATADEV_PATAPI
Definition ata.h:15
#define ATADEV_UNKNOWN
Definition ata.h:11
#define ATADEV_PATA
Definition ata.h:13
int dma_init(struct ata_drive *drive)
Sets a drive up for DMA, if both the drive and its channel's controller can do it.
Definition dma.c:195
#define ATADEV_SATAPI
Definition ata.h:16
#define ATA_STATUS_BSY
Definition ata.h:62
#define ATA_CMD_IDENTIFY_PACKET
Definition ata.h:56
#define ATA_REG_ERROR
Definition ata.h:26
#define ATA_REG_SECCOUNT0
Definition ata.h:28
#define ATA_IDENT_MAX_LBA
Definition ata.h:90
#define ATA_REG_CMD
Definition ata.h:33
#define ATA_PIO_PRI_PORT_BASE
Definition ata.h:19
#define ATA_REG_HDDEVSEL
Definition ata.h:32
#define ATA_REG_LBA2
Definition ata.h:31
ssize_t blkcache_read(void *owner, uint64_t sector, size_t count, void *buf, uint64_t nsectors, blkcache_io read)
Reads sectors of a disk through the cache.
Definition blkcache.c:367
ssize_t blkcache_write(void *owner, uint64_t sector, size_t count, void *buf, blkcache_io write)
Writes sectors of a disk through the cache: they stay dirty in it until it is flushed.
Definition blkcache.c:484
#define MIN(a, b)
Definition system.h:11
int kargs_get(const char *key, const char **value)
Looks up an argument of the kernel's command line.
Definition kargs.c:73
void kdev_blkdev_register(devid_t major, struct dev *dev)
Registers a driver as the block device of a major number.
Definition kdev.c:605
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
Definition kvmem.c:123
void kfree(void *)
Frees an object that kmalloc() gave.
Definition kvmem.c:146
void * memset(void *dst, int c, size_t n)
Sets n bytes to c.
Definition libc.c:23
#define MODULE_INIT(name, i, f)
Definition module.h:10
int posix_file_open(struct file *file)
Finishes opening a file: with O_TRUNC, a regular file is truncated to 0 bytes.
Definition open.c:17
int pci_irq(struct pci_dev *dev)
Finds the IRQ that a function's interrupt pin comes to.
Definition pci.c:367
uint16_t pci_reg16_read(struct pci_dev *dev, uint8_t off)
Reads a 16-bit configuration register.
Definition pci.c:130
int pci_scan_device(uint8_t class, uint8_t subclass, struct pci_dev *_dev, size_t nr)
Finds the functions of a class and subclass, on bus 0.
Definition pci.c:244
uint32_t pci_read_bar(struct pci_dev *dev, uint8_t id)
Reads a base address register as it is, flag bits included.
Definition pci.c:285
void pci_reg16_write(struct pci_dev *dev, uint8_t off, uint16_t val)
Writes a 16-bit configuration register: the 32-bit register it's in is read, changed and written back...
Definition pci.c:170
ssize_t posix_file_read(struct file *file, struct iobuf *io)
Reads from an open file at its offset, and moves the offset past what was read.
Definition read.c:29
ssize_t posix_file_write(struct file *file, struct iobuf *io)
Writes to an open file at its offset, and moves the offset past what was written.
Definition write.c:25
int printk(const char *fmt,...)
Writes a kernel message, to the message buffer and the consoles.
Definition printk.c:249
int sched_running
Definition sched.c:367
#define curthread
Definition sched.h:12
#define NULL
Definition stddef.h:27
unsigned int uint32_t
Definition stddef.h:22
unsigned char uint8_t
Definition stddef.h:20
unsigned long long int uint64_t
Definition stddef.h:23
unsigned short int uint16_t
Definition stddef.h:21
An IDE channel, with the master and slave drives on it.
Definition ata.h:107
int irq
Definition ata.h:112
struct waitq wait
Definition ata.h:117
int busy
one command at a time: whether one is running, and the requests waiting for the channel
Definition ata.h:116
struct ioaddr base
the command block's registers, and the bus master's for DMA (whose address is 0 if the controller has...
Definition ata.h:110
struct ioaddr bm
Definition ata.h:111
A drive on a channel.
Definition ata.h:126
uint8_t id
Definition ata.h:131
uint8_t slave
Definition ata.h:134
struct ioaddr ctrl
Definition ata.h:128
struct ioaddr base
Definition ata.h:127
ssize_t(*) read(struct ata_drive *drive, uint64_t lba, size_t count, void *buf)
Definition ata.h:147
struct ata_channel * channel
Definition ata.h:129
uint16_t capabilities
Definition ata.h:141
size_t psize[4]
Definition ata.h:136
uint64_t max_lba
Definition ata.h:143
uint16_t type
Definition ata.h:133
ssize_t(*) write(struct ata_drive *drive, uint64_t lba, size_t count, void *buf)
Definition ata.h:148
uint32_t command_sets
Definition ata.h:142
uint8_t mode
Definition ata.h:132
uint16_t signature
Definition ata.h:140
size_t poff[4]
Definition ata.h:135
char model[41]
Definition ata.h:144
A device driver: its operations, any of which may be NULL.
Definition dev.h:28
Which device: its kind (S_IFCHR or S_IFBLK) and numbers.
Definition dev.h:21
devid_t minor
Definition dev.h:24
Where a device's registers are.
Definition io.h:95
uintptr_t addr
Definition io.h:97
char type
Definition io.h:96
A partition table entry.
Definition mbr.h:17
uint32_t start_lba
Definition mbr.h:28
uint32_t sectors_count
Definition mbr.h:29
uint8_t type
Definition mbr.h:23
The master boot record.
Definition mbr.h:33
uint16_t boot_signature
Definition mbr.h:41
struct mbr_part ptab[4]
Definition mbr.h:40
A PCI function: its bus, device (slot) and function numbers.
Definition pci.h:18
uint8_t dev
Definition pci.h:20
uint8_t func
Definition pci.h:21
uint8_t bus
Definition pci.h:19
static void flush(vaddr_t sva, vaddr_t eva)
Flushes [sva, eva) from the running CPU's TLB.
Definition tlb.c:60
long int ssize_t
Definition types.h:12
long int off_t
Definition types.h:10
void waitq_wakeup_nopoll(struct waitq *waitq)
Wakes up every thread sleeping on a wait queue, but not the threads polling it.
Definition waitq.c:196
void waitq_sleep_unint(struct waitq *waitq)
Puts the current thread to sleep on a wait queue until it is woken up, whatever signals come meanwhil...
Definition waitq.c:67