From 6fb2e7e123ed3fd083ddd0428f082913c81ee656 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sat, 10 May 2025 01:31:54 -0400 Subject: kernel: ahci: Expose to devfs @ /dev/sd Signed-off-by: Ian Moffett --- sys/dev/ic/ahci.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/sys/dev/ic/ahci.c b/sys/dev/ic/ahci.c index d5d25fa..51da235 100644 --- a/sys/dev/ic/ahci.c +++ b/sys/dev/ic/ahci.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +50,7 @@ #define pr_error(...) pr_trace(__VA_ARGS__) static uint32_t devs_max = 0; +static struct bdevsw ahci_bdevsw; static struct hba_device *devs; static struct pci_device *ahci_dev; static struct timer tmr; @@ -601,6 +604,15 @@ sata_dev_rw(dev_t dev, struct sio_txn *sio, bool write) return status; } +/* + * Device interface read + */ +static int +ahci_dev_read(dev_t dev, struct sio_txn *sio, int flags) +{ + return sata_dev_rw(dev, sio, false); +} + /* * Initialize a drive on an HBA port * @@ -610,12 +622,14 @@ sata_dev_rw(dev_t dev, struct sio_txn *sio, bool write) static int ahci_init_port(struct ahci_hba *hba, uint32_t portno) { + char devname[128]; struct hba_memspace *abar = hba->io; struct hba_port *port; struct hba_device *dp; size_t clen, pagesz; uint32_t lo, hi, ssts; paddr_t fra, cmdlist, tmp; + devmajor_t major; int error; pagesz = DEFAULT_PAGESIZE; @@ -694,7 +708,17 @@ ahci_init_port(struct ahci_hba *hba, uint32_t portno) } ahci_identify(hba, port); - return 0; + + if (hba->major == 0) { + hba->major = dev_alloc_major(); + } + dp->dev = dev_alloc(hba->major); + snprintf(devname, sizeof(devname), "sd%d", dp->dev); + + /* Register the device */ + dev_register(hba->major, dp->dev, &ahci_bdevsw); + pr_trace("drive @ /dev/%s\n", devname); + return devfs_create_entry(devname, hba->major, dp->dev, 0444); } /* @@ -856,4 +880,9 @@ ahci_init(void) return 0; } +static struct bdevsw ahci_bdevsw = { + .read = ahci_dev_read, + .write = nowrite +}; + DRIVER_EXPORT(ahci_init); -- cgit v1.2.3