diff options
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/ic/ahci.c | 12 | ||||
-rw-r--r-- | sys/dev/ic/ahci_ctl.c | 63 |
2 files changed, 75 insertions, 0 deletions
diff --git a/sys/dev/ic/ahci.c b/sys/dev/ic/ahci.c index 246adde..8b72cde 100644 --- a/sys/dev/ic/ahci.c +++ b/sys/dev/ic/ahci.c @@ -42,6 +42,7 @@ #include <dev/ic/ahcivar.h> #include <dev/ic/ahciregs.h> #include <fs/devfs.h> +#include <fs/ctlfs.h> #include <vm/dynalloc.h> #include <vm/physmem.h> #include <string.h> @@ -626,6 +627,7 @@ ahci_init_port(struct ahci_hba *hba, uint32_t portno) struct hba_memspace *abar = hba->io; struct hba_port *port; struct hba_device *dp; + struct ctlfs_dev dev; size_t clen, pagesz; uint32_t lo, hi, ssts; uint8_t det; @@ -721,6 +723,16 @@ ahci_init_port(struct ahci_hba *hba, uint32_t portno) /* Register the device */ dev_register(hba->major, dp->dev, &ahci_bdevsw); pr_trace("drive @ /dev/%s\n", devname); + + /* Register a control node */ + dev.mode = 0444; + ctlfs_create_node(devname, &dev); + pr_trace("drive control @ /ctl/%s/\n", devname); + + /* Register control files */ + dev.devname = devname; + dev.ops = &g_sata_bsize_ops; + ctlfs_create_entry("bsize", &dev); return devfs_create_entry(devname, hba->major, dp->dev, 0444); } diff --git a/sys/dev/ic/ahci_ctl.c b/sys/dev/ic/ahci_ctl.c new file mode 100644 index 0000000..282a141 --- /dev/null +++ b/sys/dev/ic/ahci_ctl.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <sys/errno.h> +#include <dev/ic/ahcivar.h> +#include <fs/ctlfs.h> +#include <string.h> + +static int +ctl_bsize_read(struct ctlfs_dev *cdp, struct sio_txn *sio) +{ + uint32_t bsize = AHCI_SECTOR_SIZE; + uint32_t len = sizeof(bsize); + + if (sio == NULL) { + return -EINVAL; + } + if (sio->buf == NULL) { + return -EINVAL; + } + + if (sio->len < len) { + len = sio->len; + } + + memcpy(sio->buf, &bsize, len); + return len; +} + +/* + * Operations for /ctl/sdx/bsize + */ +const struct ctlops g_sata_bsize_ops = { + .read = ctl_bsize_read, + .write = NULL, +}; |