device/ramdisk.{c,h} from bugaevc/wip-aarch64 implements a Mach
device driver that exposes a RAM-backed block device. It's
declared in aarch64/aarch64/conf.c's dev_name_list[] via the
RAMDISK_DEV_OPS macro and no other in-kernel consumer touches it;
the apparent intent (per the original commit context) was to use
it as a transport for boot modules embedded in the DTB. That
transport never landed — wip-aarch64 settled on
/chosen/multiboot,module DTB nodes via QEMU's guest-loader
instead, leaving ramdisk half-wired: conf.c references
RAMDISK_DEV_OPS but the Makefrag doesn't include ramdisk.c in
libkernel_a_SOURCES, so the branch as-is fails to link with
undefined references to ramdisk_open / ramdisk_read / etc.
Rather than wire ramdisk in to make the import link, drop it from
this submission entirely:
* Remove device/ramdisk.c, device/ramdisk.h.
* Remove the matching `#include <device/ramdisk.h>` and the
`RAMDISK_DEV_OPS,` entry from aarch64/aarch64/conf.c's
dev_name_list[] initializer.
Rationale: a RAM-backed block device is userland territory in
Mach's microkernel design. Hurd's `storeio` translator covers
the same role from the userland side — Mach exposes the raw
memory via the device port, Hurd layers the block-device
abstraction in userland where the rest of the storage stack
lives. Pulling a new in-kernel device into the port without a
concrete consumer also goes against the minimum-touch principle
the rest of this series follows.
This is the only change to a Bugaev-authored file in this series
made for architectural reasons rather than build/runtime
correctness. If reviewers (notably Sergey Bugaev, who authored
the original ramdisk driver) want it kept and wired in, this
commit is straightforward to revert; nothing later in the series
depends on its absence.
---
aarch64/aarch64/conf.c | 2 -
device/ramdisk.c | 160 -----------------------------------------
device/ramdisk.h | 47 ------------
3 files changed, 209 deletions(-)
delete mode 100644 device/ramdisk.c
delete mode 100644 device/ramdisk.h
diff --git a/aarch64/aarch64/conf.c b/aarch64/aarch64/conf.c
index 00d374eb..5b2bbeb5 100644
--- a/aarch64/aarch64/conf.c
+++ b/aarch64/aarch64/conf.c
@@ -22,7 +22,6 @@
#ifdef MACH_KMSG
#include <device/kmsg.h>
#endif
-#include <device/ramdisk.h>
struct dev_ops dev_name_list[] =
{
@@ -44,7 +43,6 @@ struct dev_ops dev_name_list[] =
nodev_async_in, nulldev_reset, nulldev_portdeath, 0,
nodev_info },
#endif
- RAMDISK_DEV_OPS,
};
int dev_name_count = sizeof(dev_name_list) / sizeof(dev_name_list[0]);
diff --git a/device/ramdisk.c b/device/ramdisk.c
deleted file mode 100644
index daf70436..00000000
--- a/device/ramdisk.c
+++ /dev/null
@@ -1,160 +0,0 @@
-#include <mach/vm_param.h>
-#include <machine/vm_param.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_user.h>
-#include <device/device_types.h>
-#include <device/ds_routines.h>
-#include <device/conf.h>
-#include <device/ramdisk.h>
-#include <kern/printf.h>
-#include <string.h>
-
-static struct ramdisk {
- void *data;
- vm_size_t size;
-} ramdisk[RAMDISK_MAX];
-
-static int ramdisk_num = 0;
-
-/* Initial ramdisks are created from the boot scripts */
-int ramdisk_create(vm_size_t size, const void *initdata, int *out_no)
-{
- struct ramdisk *rd = &ramdisk[ramdisk_num];
- int err;
-
- if(ramdisk_num >= RAMDISK_MAX)
- return -1;
-
- /* allocate the memory */
- rd->size = round_page(size);
- err = kmem_alloc(kernel_map, (vm_offset_t *) &rd->data, rd->size);
- if(err != KERN_SUCCESS)
- return err;
-
- /* initialize */
- if(initdata)
- memcpy(rd->data, initdata, rd->size);
- else
- memset(rd->data, 0, rd->size);
-
- /* report */
- if(out_no) *out_no = ramdisk_num;
- printf("%s%d: %lu bytes @%p\n", RAMDISK_NAME, ramdisk_num,
- (unsigned long) rd->size, rd->data);
-
- ramdisk_num++;
- return KERN_SUCCESS;
-}
-
-/* On d_open() we just check whether the ramdisk exists */
-int ramdisk_open(dev_t dev, int mode, io_req_t ior)
-{
- return (dev < ramdisk_num) ? D_SUCCESS : D_NO_SUCH_DEVICE;
-}
-
-/* d_getstat() is used to query the device characteristics */
-int ramdisk_getstat(dev_t dev, dev_flavor_t flavor, dev_status_t status,
- mach_msg_type_number_t *status_count)
-{
- switch(flavor) {
- case DEV_GET_SIZE:
- status[DEV_GET_SIZE_DEVICE_SIZE] = ramdisk[dev].size;
- status[DEV_GET_SIZE_RECORD_SIZE] = RAMDISK_BLOCKSZ;
- *status_count = DEV_GET_SIZE_COUNT;
- return D_SUCCESS;
-
- case DEV_GET_RECORDS:
- status[DEV_GET_RECORDS_DEVICE_RECORDS]
- = ramdisk[dev].size / RAMDISK_BLOCKSZ;
- status[DEV_GET_RECORDS_RECORD_SIZE] = RAMDISK_BLOCKSZ;
- *status_count = DEV_GET_RECORDS_COUNT;
- return D_SUCCESS;
- }
- return D_INVALID_OPERATION;
-}
-
-/* TODO: implement freeramdisk with setstat() ? */
-
-/* Check the given io request and compute a pointer to the ramdisk data and the
- * amount to be handled. */
-static int ramdisk_ioreq(int dev, io_req_t ior, void **data, int *amt)
-{
- vm_offset_t ofs = ior->io_recnum * RAMDISK_BLOCKSZ;
- if(ofs >= ramdisk[dev].size)
- return D_INVALID_RECNUM;
-
- *data = (char*) ramdisk[dev].data + ofs;
- *amt = ior->io_count;
- if(ofs + *amt > ramdisk[dev].size)
- *amt = ramdisk[dev].size - ofs;
-
- return KERN_SUCCESS;
-}
-
-/* Copy data from a vm_map_copy by mapping it temporarily. */
-static int mem_map_cpy(void *dst, vm_map_copy_t src, int amt)
-{
- vm_offset_t srcaddr;
- int err;
-
- err = vm_map_copyout(device_io_map, &srcaddr, src);
- if (err != KERN_SUCCESS)
- return err;
-
- memcpy(dst, (void *) srcaddr, amt);
- vm_deallocate(device_io_map, srcaddr, amt);
- return KERN_SUCCESS;
-}
-
-int ramdisk_read(dev_t dev, io_req_t ior)
-{
- void *data;
- int amt, err;
-
- err = ramdisk_ioreq(dev, ior, &data, &amt);
- if(err != KERN_SUCCESS)
- return err;
-
- err = device_read_alloc (ior, ior->io_count);
- if (err != KERN_SUCCESS)
- return err;
-
- memcpy(ior->io_data, data, amt);
- ior->io_residual = ior->io_count - amt;
-
- return D_SUCCESS;
-}
-
-int ramdisk_write(dev_t dev, io_req_t ior)
-{
- void *data;
- int amt, err;
-
- err = ramdisk_ioreq(dev, ior, &data, &amt);
- if(err != KERN_SUCCESS)
- return err;
-
- if (!(ior->io_op & IO_INBAND)) {
- /* Out-of-band data is transmitted as a vm_map_copy */
- err = mem_map_cpy(data, (vm_map_copy_t) ior->io_data, amt);
- if(err != KERN_SUCCESS)
- return err;
- } else {
- /* In-band data can be accessed directly */
- memcpy(data, ior->io_data, amt);
- }
-
- ior->io_residual = ior->io_count - amt;
- return D_SUCCESS;
-}
-
-vm_offset_t ramdisk_mmap(dev_t dev, vm_offset_t off, vm_prot_t prot)
-{
- if(dev >= ramdisk_num)
- return -1;
- if(off >= ramdisk[dev].size)
- return -1;
-
- return pmap_phys_to_frame(kvtophys((vm_offset_t) ramdisk[dev].data +
off));
-}
-
diff --git a/device/ramdisk.h b/device/ramdisk.h
deleted file mode 100644
index ac71f084..00000000
--- a/device/ramdisk.h
+++ /dev/null
@@ -1,47 +0,0 @@
-#ifndef _KERN_RAMDISK_H_
-#define _KERN_RAMDISK_H_
-
-#include <vm/pmap.h>
-#include <device/io_req.h>
-#include <device/conf.h>
-
-/* Maximum number of ramdisk devices */
-#define RAMDISK_MAX 4
-
-/* The block size used (userspace requires 512) */
-#define RAMDISK_BLOCKSZ 512
-
-/* Name associated to the ramdisk major */
-#define RAMDISK_NAME "rd"
-#define RAMDISK_NAMESZ (sizeof RAMDISK_NAME + sizeof (int) * 3 + 1)
-
-/* Create a new ramdisk of the given size. On success, if out_no and/or out_ptr
- * are not NULL, the device number and pointer to the ramdisk's data are stored
- * there. Returns D_SUCCESS or D_NO_MEMORY. */
-int ramdisk_create(vm_size_t size, const void *initdata, int *out_no);
-
-/* Device operations */
-int ramdisk_open(dev_t, int, io_req_t);
-int ramdisk_getstat(dev_t, dev_flavor_t, dev_status_t, mach_msg_type_number_t
*);
-int ramdisk_read(dev_t, io_req_t);
-int ramdisk_write(dev_t, io_req_t);
-vm_offset_t ramdisk_mmap(dev_t, vm_offset_t, vm_prot_t);
-
-/* dev_ops initializer to be used from <machine>/conf.c */
-#define RAMDISK_DEV_OPS { \
- .d_name = RAMDISK_NAME, \
- .d_open = ramdisk_open, \
- .d_close = nulldev_close, \
- .d_read = ramdisk_read, \
- .d_write = ramdisk_write, \
- .d_getstat = ramdisk_getstat, \
- .d_setstat = nulldev_setstat, \
- .d_mmap = ramdisk_mmap, \
- .d_async_in = nodev_async_in, \
- .d_reset = nulldev_reset, \
- .d_port_death = nulldev_portdeath, \
- .d_subdev = 0, \
- .d_dev_info = nodev_info, \
- }
-
-#endif
--
2.54.0