diff options
author | Ian Moffett <ian@osmora.org> | 2025-05-10 01:31:54 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-05-10 01:31:54 -0400 |
commit | 6fb2e7e123ed3fd083ddd0428f082913c81ee656 (patch) | |
tree | c22f0ee682dcd85407cda657be4c8821bac7fd81 | |
parent | 1ff2cb42bf0f1b1b625df132fde2ba7a7c7e65bf (diff) |
kernel: ahci: Expose to devfs @ /dev/sd<n>
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | sys/dev/ic/ahci.c | 31 |
1 files changed, 30 insertions, 1 deletions
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 <sys/types.h> #include <sys/driver.h> +#include <sys/device.h> #include <sys/errno.h> #include <sys/syslog.h> #include <sys/sio.h> @@ -40,6 +41,7 @@ #include <dev/timer.h> #include <dev/ic/ahcivar.h> #include <dev/ic/ahciregs.h> +#include <fs/devfs.h> #include <vm/dynalloc.h> #include <vm/physmem.h> #include <string.h> @@ -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; @@ -602,6 +605,15 @@ sata_dev_rw(dev_t dev, struct sio_txn *sio, bool write) } /* + * 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 * * @hba: HBA descriptor @@ -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); |