From 335dda388a5c13edd38c87c32b72e51eaaedce75 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 22 Jul 2003 17:03:35 +0000 Subject: [PATCH] DEV messaging stage 2/4: In this stage all DEV commands are now being funneled through the message port for action by the port's beginmsg function. CONSOLE and DISK device shims replace the port with their own and then forward to the original. FB (Frame Buffer) shims supposedly do the same thing but I haven't been able to test it. I don't expect instability in mainline code but there might be easy-to-fix, and some drivers still need to be converted. See primarily: kern/kern_device.c (new dev_*() functions and inherits cdevsw code from kern/kern_conf.c), sys/device.h, and kern/subr_disk.c for the high points. In this stage all DEV messages are still acted upon synchronously in the context of the caller. We cannot create a separate handler thread until the copyin's (primarily in ioctl functions) are made thread-aware. Note that the messaging shims are going to look rather messy in these early days but as more subsystems are converted over we will begin to use pre-initialized messages and message forwarding to avoid having to constantly rebuild messages prior to use. Note that DEV itself is a mess oweing to its 4.x roots and will be cleaned up in subsequent passes. e.g. the way sub-devices inherit the main device's cdevsw was always a bad hack and it still is, and several functions (mmap, kqfilter, psize, poll) return results rather then error codes, which will be fixed since now we have a message to store the result in :-) --- sys/bus/cam/scsi/scsi_cd.c | 8 +- sys/bus/cam/scsi/scsi_da.c | 9 +- sys/bus/isa/vga_isa.c | 5 +- sys/conf/files | 3 +- sys/contrib/dev/fla/fla.c | 5 +- sys/dev/disk/ata/ata-disk.c | 7 +- sys/dev/disk/ata/ata-raid.c | 7 +- sys/dev/disk/ata/ata-raid.h | 4 +- sys/dev/disk/ata/atapi-fd.c | 7 +- sys/dev/disk/fd/fd.c | 3 +- sys/dev/disk/md/md.c | 6 +- sys/dev/drm/drm_drv.h | 14 +- sys/dev/netif/ed/if_ed_pccard.c | 7 +- sys/dev/raid/aac/aac_disk.c | 18 +- sys/dev/raid/amr/amr_disk.c | 18 +- sys/dev/raid/ida/ida_disk.c | 12 +- sys/dev/raid/mlx/mlx_disk.c | 7 +- sys/dev/raid/pst/pst-raid.c | 5 +- sys/dev/raid/twe/twe_freebsd.c | 19 +- sys/dev/raid/vinum/vinumhdr.h | 3 +- sys/dev/raid/vinum/vinumio.c | 17 +- sys/dev/video/fb/fb.c | 55 ++- sys/dev/video/fb/fbreg.h | 8 +- sys/dev/video/fb/gfb.h | 3 +- sys/dev/video/fb/vgareg.h | 3 +- sys/dev/video/gfb/gfb_pci.c | 4 +- sys/dev/video/tga/tga_pci.c | 6 +- sys/emulation/linux/linux_stats.c | 7 +- sys/i386/i386/autoconf.c | 5 +- sys/kern/kern_conf.c | 102 +--- sys/kern/kern_device.c | 678 +++++++++++++++++++++++++++ sys/kern/kern_physio.c | 3 +- sys/kern/kern_shutdown.c | 18 +- sys/kern/lwkt_msgport.c | 8 +- sys/kern/subr_disk.c | 126 +++-- sys/kern/subr_diskmbr.c | 3 +- sys/kern/subr_diskslice.c | 9 +- sys/kern/tty_cons.c | 102 ++-- sys/kern/tty_pty.c | 7 +- sys/kern/vfs_conf.c | 18 +- sys/kern/vfs_default.c | 4 +- sys/kern/vfs_subr.c | 6 +- sys/kern/vfs_vnops.c | 4 +- sys/platform/pc32/i386/autoconf.c | 5 +- sys/sys/buf.h | 9 +- sys/sys/conf.h | 109 ++--- sys/sys/device.h | 222 +++++++++ sys/sys/disk.h | 17 +- sys/sys/msgport.h | 14 +- sys/sys/msgport2.h | 10 +- sys/sys/thread.h | 3 +- sys/vfs/coda/coda_vfsops.c | 4 +- sys/vfs/isofs/cd9660/cd9660_vfsops.c | 14 +- sys/vfs/specfs/spec_vnops.c | 44 +- sys/vfs/ufs/ufs_disksubr.c | 3 +- sys/vm/device_pager.c | 21 +- sys/vm/vm_rangelock.c | 91 ++++ sys/vm/vm_swap.c | 5 +- 58 files changed, 1455 insertions(+), 479 deletions(-) create mode 100644 sys/kern/kern_device.c create mode 100644 sys/sys/device.h create mode 100644 sys/vm/vm_rangelock.c diff --git a/sys/bus/cam/scsi/scsi_cd.c b/sys/bus/cam/scsi/scsi_cd.c index 2cc16442bf..113b82afb0 100644 --- a/sys/bus/cam/scsi/scsi_cd.c +++ b/sys/bus/cam/scsi/scsi_cd.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/cam/scsi/scsi_cd.c,v 1.31.2.13 2002/11/25 05:30:31 njl Exp $ - * $DragonFly: src/sys/bus/cam/scsi/scsi_cd.c,v 1.6 2003/07/21 05:50:24 dillon Exp $ + * $DragonFly: src/sys/bus/cam/scsi/scsi_cd.c,v 1.7 2003/07/22 17:03:18 dillon Exp $ */ /* * Portions of this driver taken from the original FreeBSD cd driver. @@ -273,7 +273,6 @@ static struct cdevsw cd_cdevsw = { /* dump */ nodump, /* psize */ nopsize, }; -static struct cdevsw cddisk_cdevsw; static struct extend_array *cdperiphs; static int num_changers; @@ -498,7 +497,7 @@ cdcleanup(struct cam_periph *periph) devstat_remove_entry(&softc->device_stats); cam_extend_release(cdperiphs, periph->unit_number); if (softc->disk.d_dev) { - disk_destroy(softc->disk.d_dev); + disk_destroy(&softc->disk); } free(softc, M_DEVBUF); splx(s); @@ -638,8 +637,7 @@ cdregister(struct cam_periph *periph, void *arg) DEVSTAT_TYPE_CDROM | DEVSTAT_TYPE_IF_SCSI, DEVSTAT_PRIORITY_CD); disk_create(periph->unit_number, &softc->disk, - DSO_ONESLICE | DSO_COMPATLABEL, - &cd_cdevsw, &cddisk_cdevsw); + DSO_ONESLICE | DSO_COMPATLABEL, &cd_cdevsw); /* * Add an async callback so that we get diff --git a/sys/bus/cam/scsi/scsi_da.c b/sys/bus/cam/scsi/scsi_da.c index e05a0ca710..adc33d0ac9 100644 --- a/sys/bus/cam/scsi/scsi_da.c +++ b/sys/bus/cam/scsi/scsi_da.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/cam/scsi/scsi_da.c,v 1.42.2.36 2003/05/17 21:48:30 njl Exp $ - * $DragonFly: src/sys/bus/cam/scsi/scsi_da.c,v 1.6 2003/07/21 05:50:24 dillon Exp $ + * $DragonFly: src/sys/bus/cam/scsi/scsi_da.c,v 1.7 2003/07/22 17:03:18 dillon Exp $ */ #ifdef _KERNEL @@ -589,8 +589,6 @@ static struct cdevsw da_cdevsw = { /* psize */ nopsize }; -static struct cdevsw dadisk_cdevsw; - static SLIST_HEAD(,da_softc) softc_list; static struct extend_array *daperiphs; @@ -1155,7 +1153,7 @@ dacleanup(struct cam_periph *periph) xpt_print_path(periph->path); printf("removing device entry\n"); if (softc->disk.d_dev) { - disk_destroy(softc->disk.d_dev); + disk_destroy(&softc->disk); } free(softc, M_DEVBUF); } @@ -1307,8 +1305,7 @@ daregister(struct cam_periph *periph, void *arg) /* * Register this media as a disk */ - disk_create(periph->unit_number, &softc->disk, 0, - &da_cdevsw, &dadisk_cdevsw); + disk_create(periph->unit_number, &softc->disk, 0, &da_cdevsw); /* * Add async callbacks for bus reset and diff --git a/sys/bus/isa/vga_isa.c b/sys/bus/isa/vga_isa.c index f5be2b0767..64e2749ecb 100644 --- a/sys/bus/isa/vga_isa.c +++ b/sys/bus/isa/vga_isa.c @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/isa/vga_isa.c,v 1.17 2000/01/29 15:08:56 peter Exp $ - * $DragonFly: src/sys/bus/isa/vga_isa.c,v 1.4 2003/07/21 07:57:47 dillon Exp $ + * $DragonFly: src/sys/bus/isa/vga_isa.c,v 1.5 2003/07/22 17:03:32 dillon Exp $ */ #include "opt_vga.h" @@ -164,7 +164,8 @@ isavga_attach(device_t dev) #ifdef FB_INSTALL_CDEV /* attach a virtual frame buffer device */ - error = fb_attach(makedev(0, VGA_MKMINOR(unit)), sc->adp, &isavga_cdevsw); + sc->devt = make_dev(&isavga_cdevsw, VGA_MKMINOR(unit), 0, 0, 02660, "vga%x", VGA_MKMINOR(unit)); + error = fb_attach(sc->devt, sc->adp); if (error) return error; #endif /* FB_INSTALL_CDEV */ diff --git a/sys/conf/files b/sys/conf/files index 01525bdbe5..a9bddc30f4 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,5 +1,5 @@ # $FreeBSD: src/sys/conf/files,v 1.340.2.137 2003/06/04 17:10:30 sam Exp $ -# $DragonFly: src/sys/conf/files,v 1.7 2003/07/20 01:37:19 dillon Exp $ +# $DragonFly: src/sys/conf/files,v 1.8 2003/07/22 17:03:26 dillon Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -602,6 +602,7 @@ kern/kern_acct.c standard kern/kern_acl.c standard kern/kern_clock.c standard kern/kern_conf.c standard +kern/kern_device.c standard kern/kern_descrip.c standard kern/kern_environment.c standard kern/kern_event.c standard diff --git a/sys/contrib/dev/fla/fla.c b/sys/contrib/dev/fla/fla.c index 6ecb59b5db..03abb0707d 100644 --- a/sys/contrib/dev/fla/fla.c +++ b/sys/contrib/dev/fla/fla.c @@ -7,7 +7,7 @@ * ---------------------------------------------------------------------------- * * $FreeBSD: src/sys/contrib/dev/fla/fla.c,v 1.16 1999/12/08 04:45:16 ken Exp $ - * $DragonFly: src/sys/contrib/dev/fla/Attic/fla.c,v 1.4 2003/07/21 07:57:39 dillon Exp $ + * $DragonFly: src/sys/contrib/dev/fla/Attic/fla.c,v 1.5 2003/07/22 17:03:26 dillon Exp $ * */ @@ -76,7 +76,6 @@ static struct cdevsw fla_cdevsw = { /* dump */ nodump, /* psize */ nopsize }; -static struct cdevsw fladisk_cdevsw; void * doc2k_malloc(int bytes) @@ -334,7 +333,7 @@ flaattach (device_t dev) DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER, DEVSTAT_PRIORITY_DISK); - sc->dev = disk_create(unit, &sc->disk, 0, &fla_cdevsw, &fladisk_cdevsw); + sc->dev = disk_create(unit, &sc->disk, 0, &fla_cdevsw); sc->dev->si_drv1 = sc; sc->unit = unit; diff --git a/sys/dev/disk/ata/ata-disk.c b/sys/dev/disk/ata/ata-disk.c index 9c35db7fd6..d8796288f7 100644 --- a/sys/dev/disk/ata/ata-disk.c +++ b/sys/dev/disk/ata/ata-disk.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ata/ata-disk.c,v 1.60.2.24 2003/01/30 07:19:59 sos Exp $ - * $DragonFly: src/sys/dev/disk/ata/ata-disk.c,v 1.5 2003/07/21 05:50:27 dillon Exp $ + * $DragonFly: src/sys/dev/disk/ata/ata-disk.c,v 1.6 2003/07/22 17:03:27 dillon Exp $ */ #include "opt_ata.h" @@ -79,7 +79,6 @@ static struct cdevsw ad_cdevsw = { /* dump */ addump, /* psize */ nopsize }; -static struct cdevsw addisk_cdevsw; /* prototypes */ static void ad_invalidatequeue(struct ad_softc *, struct ad_request *); @@ -203,7 +202,7 @@ ad_attach(struct ata_device *atadev) DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_IDE, DEVSTAT_PRIORITY_DISK); - dev = disk_create(adp->lun, &adp->disk, 0, &ad_cdevsw, &addisk_cdevsw); + dev = disk_create(adp->lun, &adp->disk, 0, &ad_cdevsw); dev->si_drv1 = adp; dev->si_iosize_max = 256 * DEV_BSIZE; adp->dev = dev; @@ -257,8 +256,8 @@ ad_detach(struct ata_device *atadev, int flush) /* get rid of flush XXX SOS */ biodone(bp); } disk_invalidate(&adp->disk); - disk_destroy(adp->dev); devstat_remove_entry(&adp->stats); + disk_destroy(&adp->disk); if (flush) { if (ata_command(atadev, ATA_C_FLUSHCACHE, 0, 0, 0, ATA_WAIT_READY)) ata_prtdev(atadev, "flushing cache on detach failed\n"); diff --git a/sys/dev/disk/ata/ata-raid.c b/sys/dev/disk/ata/ata-raid.c index bac923b702..190e7e54ba 100644 --- a/sys/dev/disk/ata/ata-raid.c +++ b/sys/dev/disk/ata/ata-raid.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ata/ata-raid.c,v 1.3.2.19 2003/01/30 07:19:59 sos Exp $ - * $DragonFly: src/sys/dev/disk/ata/ata-raid.c,v 1.6 2003/07/21 05:50:27 dillon Exp $ + * $DragonFly: src/sys/dev/disk/ata/ata-raid.c,v 1.7 2003/07/22 17:03:27 dillon Exp $ */ #include "opt_ata.h" @@ -71,7 +71,6 @@ static struct cdevsw ar_cdevsw = { /* dump */ nodump, /* psize */ nopsize }; -static struct cdevsw ardisk_cdevsw; /* prototypes */ static void ar_attach_raid(struct ar_softc *, int); @@ -188,7 +187,7 @@ ar_attach_raid(struct ar_softc *rdp, int update) int disk; ar_config_changed(rdp, update); - dev = disk_create(rdp->lun, &rdp->disk, 0, &ar_cdevsw, &ardisk_cdevsw); + dev = disk_create(rdp->lun, &rdp->disk, 0, &ar_cdevsw); dev->si_drv1 = rdp; dev->si_iosize_max = 256 * DEV_BSIZE; rdp->dev = dev; @@ -410,7 +409,7 @@ ata_raid_delete(int array) else ar_highpoint_write_conf(rdp); disk_invalidate(&rdp->disk); - disk_destroy(rdp->dev); + disk_destroy(&rdp->disk); free(rdp, M_AR); ar_table[array] = NULL; return 0; diff --git a/sys/dev/disk/ata/ata-raid.h b/sys/dev/disk/ata/ata-raid.h index d495a53016..820fb1de87 100644 --- a/sys/dev/disk/ata/ata-raid.h +++ b/sys/dev/disk/ata/ata-raid.h @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ata/ata-raid.h,v 1.2.2.8 2002/04/11 09:31:57 sos Exp $ - * $DragonFly: src/sys/dev/disk/ata/ata-raid.h,v 1.2 2003/06/17 04:28:22 dillon Exp $ + * $DragonFly: src/sys/dev/disk/ata/ata-raid.h,v 1.3 2003/07/22 17:03:27 dillon Exp $ */ /* misc defines */ @@ -36,7 +36,7 @@ #define AR_READ 0x01 #define AR_WRITE 0x02 #define AR_WAIT 0x04 -#define AR_STRATEGY(x) (x)->b_dev->si_disk->d_devsw->d_strategy((x)) +#define AR_STRATEGY(x) dev_port_dstrategy((x)->b_dev->si_disk->d_fwdport, (x)->b_dev->si_disk->d_dev, x) #define AD_SOFTC(x) ((struct ad_softc *)(x.device->driver)) #define ATA_MAGIC "FreeBSD ATA driver RAID " diff --git a/sys/dev/disk/ata/atapi-fd.c b/sys/dev/disk/ata/atapi-fd.c index f925c4f164..1bb45005f9 100644 --- a/sys/dev/disk/ata/atapi-fd.c +++ b/sys/dev/disk/ata/atapi-fd.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ata/atapi-fd.c,v 1.44.2.9 2002/07/31 11:19:26 sos Exp $ - * $DragonFly: src/sys/dev/disk/ata/atapi-fd.c,v 1.5 2003/07/21 05:50:27 dillon Exp $ + * $DragonFly: src/sys/dev/disk/ata/atapi-fd.c,v 1.6 2003/07/22 17:03:27 dillon Exp $ */ #include @@ -70,7 +70,6 @@ static struct cdevsw afd_cdevsw = { /* dump */ nodump, /* psize */ nopsize }; -static struct cdevsw afddisk_cdevsw; /* prototypes */ static int afd_sense(struct afd_softc *); @@ -110,7 +109,7 @@ afdattach(struct ata_device *atadev) DEVSTAT_NO_ORDERED_TAGS, DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_IDE, DEVSTAT_PRIORITY_WFD); - dev = disk_create(fdp->lun, &fdp->disk, 0, &afd_cdevsw, &afddisk_cdevsw); + dev = disk_create(fdp->lun, &fdp->disk, 0, &afd_cdevsw); dev->si_drv1 = fdp; fdp->dev = dev; @@ -139,7 +138,7 @@ afddetach(struct ata_device *atadev) biodone(bp); } disk_invalidate(&fdp->disk); - disk_destroy(fdp->dev); + disk_destroy(&fdp->disk); devstat_remove_entry(&fdp->stats); ata_free_name(atadev); ata_free_lun(&afd_lun_map, fdp->lun); diff --git a/sys/dev/disk/fd/fd.c b/sys/dev/disk/fd/fd.c index c23511da38..472e47bcd5 100644 --- a/sys/dev/disk/fd/fd.c +++ b/sys/dev/disk/fd/fd.c @@ -51,7 +51,7 @@ * * from: @(#)fd.c 7.4 (Berkeley) 5/25/91 * $FreeBSD: src/sys/isa/fd.c,v 1.176.2.8 2002/05/15 21:56:14 joerg Exp $ - * $DragonFly: src/sys/dev/disk/fd/fd.c,v 1.7 2003/07/21 05:50:42 dillon Exp $ + * $DragonFly: src/sys/dev/disk/fd/fd.c,v 1.8 2003/07/22 17:03:32 dillon Exp $ * */ @@ -72,6 +72,7 @@ #include #include #include +#include #include #include diff --git a/sys/dev/disk/md/md.c b/sys/dev/disk/md/md.c index 5d528d88d5..d5c83a9cc1 100644 --- a/sys/dev/disk/md/md.c +++ b/sys/dev/disk/md/md.c @@ -7,7 +7,7 @@ * ---------------------------------------------------------------------------- * * $FreeBSD: src/sys/dev/md/md.c,v 1.8.2.2 2002/08/19 17:43:34 jdp Exp $ - * $DragonFly: src/sys/dev/disk/md/md.c,v 1.5 2003/07/21 05:50:32 dillon Exp $ + * $DragonFly: src/sys/dev/disk/md/md.c,v 1.6 2003/07/22 17:03:30 dillon Exp $ * */ @@ -84,8 +84,6 @@ static struct cdevsw md_cdevsw = { /* psize */ nopsize, }; -static struct cdevsw mddisk_cdevsw; - struct md_s { int unit; struct devstat stats; @@ -356,7 +354,7 @@ mdcreate(void) DEVSTAT_NO_ORDERED_TAGS, DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER, DEVSTAT_PRIORITY_OTHER); - sc->dev = disk_create(sc->unit, &sc->disk, 0, &md_cdevsw, &mddisk_cdevsw); + sc->dev = disk_create(sc->unit, &sc->disk, 0, &md_cdevsw); sc->dev->si_drv1 = sc; return (sc); } diff --git a/sys/dev/drm/drm_drv.h b/sys/dev/drm/drm_drv.h index 9498c44eed..cdc26c3dae 100644 --- a/sys/dev/drm/drm_drv.h +++ b/sys/dev/drm/drm_drv.h @@ -29,7 +29,7 @@ * Gareth Hughes * * $FreeBSD: src/sys/dev/drm/drm_drv.h,v 1.13.2.1 2003/04/26 07:05:28 anholt Exp $ - * $DragonFly: src/sys/dev/drm/Attic/drm_drv.h,v 1.4 2003/07/21 05:50:29 dillon Exp $ + * $DragonFly: src/sys/dev/drm/Attic/drm_drv.h,v 1.5 2003/07/22 17:03:28 dillon Exp $ */ /* @@ -213,12 +213,12 @@ static struct cdevsw DRM(cdevsw) = { .d_port = NULL, .d_autoq = 0, - .d_open = DRM( open ), - .d_close = DRM( close ), - .d_read = DRM( read ), - .d_ioctl = DRM( ioctl ), - .d_poll = DRM( poll ), - .d_mmap = DRM( mmap ) + .old_open = DRM( open ), + .old_close = DRM( close ), + .old_read = DRM( read ), + .old_ioctl = DRM( ioctl ), + .old_poll = DRM( poll ), + .old_mmap = DRM( mmap ) }; static int DRM(probe)(device_t dev) diff --git a/sys/dev/netif/ed/if_ed_pccard.c b/sys/dev/netif/ed/if_ed_pccard.c index d60682372a..60ae5e4352 100644 --- a/sys/dev/netif/ed/if_ed_pccard.c +++ b/sys/dev/netif/ed/if_ed_pccard.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ed/if_ed_pccard.c,v 1.9.2.6 2001/07/25 18:06:01 iedowse Exp $ - * $DragonFly: src/sys/dev/netif/ed/if_ed_pccard.c,v 1.3 2003/06/25 05:22:29 dillon Exp $ + * $DragonFly: src/sys/dev/netif/ed/if_ed_pccard.c,v 1.4 2003/07/22 17:03:28 dillon Exp $ */ #include @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -322,7 +323,7 @@ ed_pccard_memwrite(device_t dev, off_t offset, u_char byte) uios.uio_td = NULL; d = makedev(CARD_MAJOR, devi->slt->slotnum); - return devsw(d)->d_write(d, &uios, 0); + return (dev_dwrite(d, &uios, 0)); } static int @@ -347,7 +348,7 @@ ed_pccard_memread(device_t dev, off_t offset, u_char *buf, int size) uios.uio_td = NULL; d = makedev(CARD_MAJOR, devi->slt->slotnum); - return devsw(d)->d_read(d, &uios, 0); + return (dev_dread(d, &uios, 0)); } /* diff --git a/sys/dev/raid/aac/aac_disk.c b/sys/dev/raid/aac/aac_disk.c index 129749d7fa..8176f80713 100644 --- a/sys/dev/raid/aac/aac_disk.c +++ b/sys/dev/raid/aac/aac_disk.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/aac/aac_disk.c,v 1.3.2.8 2003/01/11 18:39:39 scottl Exp $ - * $DragonFly: src/sys/dev/raid/aac/aac_disk.c,v 1.3 2003/07/21 05:50:26 dillon Exp $ + * $DragonFly: src/sys/dev/raid/aac/aac_disk.c,v 1.4 2003/07/22 17:03:27 dillon Exp $ */ #include "opt_aac.h" @@ -91,10 +91,6 @@ static struct cdevsw aac_disk_cdevsw = { }; devclass_t aac_disk_devclass; -static struct cdevsw aac_disk_disk_cdevsw; -#ifdef FREEBSD_4 -static int disks_registered = 0; -#endif static device_method_t aac_disk_methods[] = { DEVMETHOD(device_probe, aac_disk_probe), @@ -381,11 +377,8 @@ aac_disk_attach(device_t dev) /* attach a generic disk device to ourselves */ sc->ad_dev_t = disk_create(device_get_unit(dev), &sc->ad_disk, 0, - &aac_disk_cdevsw, &aac_disk_disk_cdevsw); + &aac_disk_cdevsw); sc->ad_dev_t->si_drv1 = sc; -#ifdef FREEBSD_4 - disks_registered++; -#endif sc->ad_dev_t->si_iosize_max = aac_iosize_max; sc->unit = device_get_unit(dev); @@ -409,11 +402,6 @@ aac_disk_detach(device_t dev) return(EBUSY); devstat_remove_entry(&sc->ad_stats); - disk_destroy(sc->ad_dev_t); -#ifdef FREEBSD_4 - if (--disks_registered == 0) - cdevsw_remove(&aac_disk_cdevsw); -#endif - + disk_destroy(&sc->ad_disk); return(0); } diff --git a/sys/dev/raid/amr/amr_disk.c b/sys/dev/raid/amr/amr_disk.c index 5506856536..16995bf800 100644 --- a/sys/dev/raid/amr/amr_disk.c +++ b/sys/dev/raid/amr/amr_disk.c @@ -54,7 +54,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/amr/amr_disk.c,v 1.5.2.5 2002/12/20 15:12:04 emoore Exp $ - * $DragonFly: src/sys/dev/raid/amr/amr_disk.c,v 1.3 2003/07/21 05:50:26 dillon Exp $ + * $DragonFly: src/sys/dev/raid/amr/amr_disk.c,v 1.4 2003/07/22 17:03:27 dillon Exp $ */ /* @@ -111,10 +111,6 @@ static struct cdevsw amrd_cdevsw = { }; static devclass_t amrd_devclass; -static struct cdevsw amrddisk_cdevsw; -#ifdef FREEBSD_4 -static int disks_registered = 0; -#endif static device_method_t amrd_methods[] = { DEVMETHOD(device_probe, amrd_probe), @@ -273,11 +269,8 @@ amrd_attach(device_t dev) DEVSTAT_TYPE_STORARRAY | DEVSTAT_TYPE_IF_OTHER, DEVSTAT_PRIORITY_ARRAY); - sc->amrd_dev_t = disk_create(sc->amrd_unit, &sc->amrd_disk, 0, &amrd_cdevsw, &amrddisk_cdevsw); + sc->amrd_dev_t = disk_create(sc->amrd_unit, &sc->amrd_disk, 0, &amrd_cdevsw); sc->amrd_dev_t->si_drv1 = sc; -#ifdef FREEBSD_4 - disks_registered++; -#endif /* set maximum I/O size to match the maximum s/g size */ sc->amrd_dev_t->si_iosize_max = (AMR_NSEG - 1) * PAGE_SIZE; @@ -296,12 +289,7 @@ amrd_detach(device_t dev) return(EBUSY); devstat_remove_entry(&sc->amrd_stats); -#ifdef FREEBSD_4 - if (--disks_registered == 0) - cdevsw_remove(&amrddisk_cdevsw); -#else - disk_destroy(sc->amrd_dev_t); -#endif + disk_destroy(&sc->amrd_disk); return(0); } diff --git a/sys/dev/raid/ida/ida_disk.c b/sys/dev/raid/ida/ida_disk.c index 26a32d4295..f3e25d11bb 100644 --- a/sys/dev/raid/ida/ida_disk.c +++ b/sys/dev/raid/ida/ida_disk.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/ida/ida_disk.c,v 1.12.2.6 2001/11/27 20:21:02 ps Exp $ - * $DragonFly: src/sys/dev/raid/ida/ida_disk.c,v 1.4 2003/07/21 05:50:31 dillon Exp $ + * $DragonFly: src/sys/dev/raid/ida/ida_disk.c,v 1.5 2003/07/22 17:03:29 dillon Exp $ */ /* @@ -91,8 +91,6 @@ static struct cdevsw id_cdevsw = { }; static devclass_t idad_devclass; -static struct cdevsw idaddisk_cdevsw; -static int disks_registered = 0; static device_method_t idad_methods[] = { DEVMETHOD(device_probe, idad_probe), @@ -312,12 +310,10 @@ idad_attach(device_t dev) DEVSTAT_TYPE_STORARRAY| DEVSTAT_TYPE_IF_OTHER, DEVSTAT_PRIORITY_ARRAY); - dsk = disk_create(drv->unit, &drv->disk, 0, - &id_cdevsw, &idaddisk_cdevsw); + dsk = disk_create(drv->unit, &drv->disk, 0, &id_cdevsw); dsk->si_drv1 = drv; dsk->si_iosize_max = DFLTPHYS; /* XXX guess? */ - disks_registered++; return (0); } @@ -329,8 +325,6 @@ idad_detach(device_t dev) drv = (struct idad_softc *)device_get_softc(dev); devstat_remove_entry(&drv->stats); - - if (--disks_registered == 0) - cdevsw_remove(&idaddisk_cdevsw); + disk_destroy(&drv->disk); return (0); } diff --git a/sys/dev/raid/mlx/mlx_disk.c b/sys/dev/raid/mlx/mlx_disk.c index ec2600db9b..2bb08348b6 100644 --- a/sys/dev/raid/mlx/mlx_disk.c +++ b/sys/dev/raid/mlx/mlx_disk.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/mlx/mlx_disk.c,v 1.8.2.4 2001/06/25 04:37:51 msmith Exp $ - * $DragonFly: src/sys/dev/raid/mlx/mlx_disk.c,v 1.4 2003/07/21 05:50:32 dillon Exp $ + * $DragonFly: src/sys/dev/raid/mlx/mlx_disk.c,v 1.5 2003/07/22 17:03:30 dillon Exp $ */ /* @@ -81,7 +81,6 @@ static struct cdevsw mlxd_cdevsw = { }; devclass_t mlxd_devclass; -static struct cdevsw mlxddisk_cdevsw; static device_method_t mlxd_methods[] = { DEVMETHOD(device_probe, mlxd_probe), @@ -262,7 +261,7 @@ mlxd_attach(device_t dev) DEVSTAT_TYPE_STORARRAY | DEVSTAT_TYPE_IF_OTHER, DEVSTAT_PRIORITY_ARRAY); - dsk = disk_create(sc->mlxd_unit, &sc->mlxd_disk, 0, &mlxd_cdevsw, &mlxddisk_cdevsw); + dsk = disk_create(sc->mlxd_unit, &sc->mlxd_disk, 0, &mlxd_cdevsw); dsk->si_drv1 = sc; sc->mlxd_dev_t = dsk; @@ -285,7 +284,7 @@ mlxd_detach(device_t dev) debug_called(1); devstat_remove_entry(&sc->mlxd_stats); - disk_destroy(sc->mlxd_dev_t); + disk_destroy(&sc->mlxd_disk); return(0); } diff --git a/sys/dev/raid/pst/pst-raid.c b/sys/dev/raid/pst/pst-raid.c index 2322971d1b..4f1845b45a 100644 --- a/sys/dev/raid/pst/pst-raid.c +++ b/sys/dev/raid/pst/pst-raid.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/pst/pst-raid.c,v 1.2.2.1 2002/08/18 12:32:36 sos Exp $ - * $DragonFly: src/sys/dev/raid/pst/pst-raid.c,v 1.3 2003/07/21 05:50:34 dillon Exp $ + * $DragonFly: src/sys/dev/raid/pst/pst-raid.c,v 1.4 2003/07/22 17:03:30 dillon Exp $ */ #include @@ -71,7 +71,6 @@ static struct cdevsw pst_cdevsw = { /* dump */ nodump, /* psize */ nopsize }; -static struct cdevsw pstdisk_cdevsw; struct pst_softc { struct iop_softc *iop; @@ -168,7 +167,7 @@ pst_attach(device_t dev) bufq_init(&psc->queue); - psc->device = disk_create(lun, &psc->disk, 0, &pst_cdevsw, &pstdisk_cdevsw); + psc->device = disk_create(lun, &psc->disk, 0, &pst_cdevsw); psc->device->si_drv1 = psc; psc->device->si_iosize_max = 64 * 1024; /*I2O_SGL_MAX_SEGS * PAGE_SIZE;*/ diff --git a/sys/dev/raid/twe/twe_freebsd.c b/sys/dev/raid/twe/twe_freebsd.c index 9ac69e34cd..9519b022b3 100644 --- a/sys/dev/raid/twe/twe_freebsd.c +++ b/sys/dev/raid/twe/twe_freebsd.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/twe/twe_freebsd.c,v 1.2.2.5 2002/03/07 09:57:02 msmith Exp $ - * $DragonFly: src/sys/dev/raid/twe/twe_freebsd.c,v 1.3 2003/07/21 05:50:37 dillon Exp $ + * $DragonFly: src/sys/dev/raid/twe/twe_freebsd.c,v 1.4 2003/07/22 17:03:31 dillon Exp $ */ /* @@ -613,11 +613,6 @@ static struct cdevsw twed_cdevsw = { nopsize }; -static struct cdevsw tweddisk_cdevsw; -#ifdef FREEBSD_4 -static int disks_registered = 0; -#endif - /******************************************************************************** * Handle open from generic layer. * @@ -811,13 +806,10 @@ twed_attach(device_t dev) DEVSTAT_PRIORITY_ARRAY); /* attach a generic disk device to ourselves */ - dsk = disk_create(device_get_unit(dev), &sc->twed_disk, 0, &twed_cdevsw, &tweddisk_cdevsw); + dsk = disk_create(device_get_unit(dev), &sc->twed_disk, 0, &twed_cdevsw); dsk->si_drv1 = sc; dsk->si_drv2 = &sc->twed_drive->td_unit; sc->twed_dev_t = dsk; -#ifdef FREEBSD_4 - disks_registered++; -#endif /* set the maximum I/O size to the theoretical maximum allowed by the S/G list size */ dsk->si_iosize_max = (TWE_MAX_SGL_LENGTH - 1) * PAGE_SIZE; @@ -839,12 +831,7 @@ twed_detach(device_t dev) return(EBUSY); devstat_remove_entry(&sc->twed_stats); -#ifdef FREEBSD_4 - if (--disks_registered == 0) - cdevsw_remove(&tweddisk_cdevsw); -#else - disk_destroy(sc->twed_dev_t); -#endif + disk_destroy(&sc->twed_disk); return(0); } diff --git a/sys/dev/raid/vinum/vinumhdr.h b/sys/dev/raid/vinum/vinumhdr.h index 9efff70cbd..078c77c789 100644 --- a/sys/dev/raid/vinum/vinumhdr.h +++ b/sys/dev/raid/vinum/vinumhdr.h @@ -38,7 +38,7 @@ /* * $Id: vinumhdr.h,v 1.18 2001/01/04 00:14:14 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinumhdr.h,v 1.16.2.1 2001/03/13 02:59:43 grog Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinumhdr.h,v 1.3 2003/06/19 01:55:04 dillon Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinumhdr.h,v 1.4 2003/07/22 17:03:31 dillon Exp $ */ #include @@ -63,6 +63,7 @@ #include #include #include +#include #ifdef _KERNEL #include #include diff --git a/sys/dev/raid/vinum/vinumio.c b/sys/dev/raid/vinum/vinumio.c index 6b9b9e8bc1..742c9edb48 100644 --- a/sys/dev/raid/vinum/vinumio.c +++ b/sys/dev/raid/vinum/vinumio.c @@ -35,7 +35,7 @@ * * $Id: vinumio.c,v 1.30 2000/05/10 23:23:30 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinumio.c,v 1.52.2.6 2002/05/02 08:43:44 grog Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinumio.c,v 1.3 2003/06/23 17:55:36 dillon Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinumio.c,v 1.4 2003/07/22 17:03:31 dillon Exp $ */ #include @@ -56,7 +56,6 @@ open_drive(struct drive *drive, struct proc *p, int verbose) int devminor; /* minor devs for disk device */ int unit; char *dname; - struct cdevsw *dsw; /* pointer to cdevsw entry */ if (bcmp(drive->devicename, "/dev/", 5)) /* device name doesn't start with /dev */ return ENOENT; /* give up */ @@ -140,11 +139,10 @@ open_drive(struct drive *drive, struct proc *p, int verbose) return ENODEV; drive->dev->si_iosize_max = DFLTPHYS; - dsw = devsw(drive->dev); - if (dsw == NULL) + if (dev_dport(drive->dev) == NULL) drive->lasterror = ENOENT; else - drive->lasterror = (dsw->d_open) (drive->dev, FWRITE, 0, NULL); + drive->lasterror = dev_dopen(drive->dev, FWRITE, 0, NULL); if (drive->lasterror != 0) { /* failed */ drive->state = drive_down; /* just force it down */ @@ -222,7 +220,8 @@ init_drive(struct drive *drive, int verbose) if (drive->lasterror) return drive->lasterror; - drive->lasterror = (*devsw(drive->dev)->d_ioctl) (drive->dev, + drive->lasterror = dev_dioctl( + drive->dev, DIOCGPART, (caddr_t) & drive->partinfo, FREAD, @@ -272,7 +271,7 @@ close_locked_drive(struct drive *drive) * the queues, which spec_close() will try to * do. Get rid of them here first. */ - drive->lasterror = (*devsw(drive->dev)->d_close) (drive->dev, 0, 0, NULL); + drive->lasterror = dev_dclose(drive->dev, 0, 0, NULL); drive->flags &= ~VF_OPEN; /* no longer open */ } @@ -666,7 +665,7 @@ daemon_save_config(void) if ((drive->state != drive_unallocated) && (drive->state != drive_referenced)) { /* and it's a real drive */ wlabel_on = 1; /* enable writing the label */ - error = (*devsw(drive->dev)->d_ioctl) (drive->dev, /* make the label writeable */ + error = dev_dioctl(drive->dev, /* make the label writeable */ DIOCWLABEL, (caddr_t) & wlabel_on, FWRITE, @@ -679,7 +678,7 @@ daemon_save_config(void) error = write_drive(drive, config, MAXCONFIG, VINUM_CONFIG_OFFSET + MAXCONFIG); /* second copy */ wlabel_on = 0; /* enable writing the label */ if (error == 0) - error = (*devsw(drive->dev)->d_ioctl) (drive->dev, /* make the label non-writeable again */ + error = dev_dioctl(drive->dev, /* make the label non-writeable again */ DIOCWLABEL, (caddr_t) & wlabel_on, FWRITE, diff --git a/sys/dev/video/fb/fb.c b/sys/dev/video/fb/fb.c index bb50038269..cc2f7b2e5e 100644 --- a/sys/dev/video/fb/fb.c +++ b/sys/dev/video/fb/fb.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/fb/fb.c,v 1.11.2.2 2000/08/02 22:35:22 peter Exp $ - * $DragonFly: src/sys/dev/video/fb/fb.c,v 1.4 2003/07/21 07:57:40 dillon Exp $ + * $DragonFly: src/sys/dev/video/fb/fb.c,v 1.5 2003/07/22 17:03:28 dillon Exp $ */ #include "opt_fb.h" @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -61,8 +62,8 @@ static video_switch_t *vidsw_ini; video_switch_t **vidsw = &vidsw_ini; #ifdef FB_INSTALL_CDEV -static struct cdevsw *vidcdevsw_ini; -static struct cdevsw **vidcdevsw = &vidcdevsw_ini; +static struct lwkt_port *vidcdevsw_ini; +static struct lwkt_port **vidcdevsw = &vidcdevsw_ini; #endif #define ARRAY_DELTA 4 @@ -73,7 +74,7 @@ vid_realloc_array(void) video_adapter_t **new_adp; video_switch_t **new_vidsw; #ifdef FB_INSTALL_CDEV - struct cdevsw **new_cdevsw; + struct lwkt_port **new_cdevsw; #endif int newsize; int s; @@ -391,8 +392,11 @@ vfbattach(void *arg) PSEUDO_SET(vfbattach, fb); +/* + * Note: dev represents the actual video device, not the frame buffer + */ int -fb_attach(dev_t dev, video_adapter_t *adp, struct cdevsw *cdevsw) +fb_attach(dev_t dev, video_adapter_t *adp) { int s; @@ -403,15 +407,19 @@ fb_attach(dev_t dev, video_adapter_t *adp, struct cdevsw *cdevsw) s = spltty(); adp->va_minor = minor(dev); - vidcdevsw[adp->va_index] = cdevsw; + vidcdevsw[adp->va_index] = dev_dport(dev); splx(s); printf("fb%d at %s%d\n", adp->va_index, adp->va_name, adp->va_unit); return 0; } +#if 0 /* never seems to be called */ +/* + * Note: dev represents the actual video device, not the frame buffer + */ int -fb_detach(dev_t dev, video_adapter_t *adp, struct cdevsw *cdevsw) +fb_detach(dev_t dev, video_adapter_t *adp) { int s; @@ -419,7 +427,7 @@ fb_detach(dev_t dev, video_adapter_t *adp, struct cdevsw *cdevsw) return EINVAL; if (adapter[adp->va_index] != adp) return EINVAL; - if (vidcdevsw[adp->va_index] != cdevsw) + if (vidcdevsw[adp->va_index] != port) return EINVAL; s = spltty(); @@ -427,6 +435,7 @@ fb_detach(dev_t dev, video_adapter_t *adp, struct cdevsw *cdevsw) splx(s); return 0; } +#endif static int fbopen(dev_t dev, int flag, int mode, struct thread *td) @@ -438,8 +447,9 @@ fbopen(dev_t dev, int flag, int mode, struct thread *td) return ENXIO; if (vidcdevsw[unit] == NULL) return ENXIO; - return (*vidcdevsw[unit]->d_open)(makedev(0, adapter[unit]->va_minor), - flag, mode, td); + return dev_port_dopen(vidcdevsw[unit], + makedev(0, adapter[unit]->va_minor), + flag, mode, td); } static int @@ -450,8 +460,9 @@ fbclose(dev_t dev, int flag, int mode, struct thread *td) unit = FB_UNIT(dev); if (vidcdevsw[unit] == NULL) return ENXIO; - return (*vidcdevsw[unit]->d_close)(makedev(0, adapter[unit]->va_minor), - flag, mode, td); + return dev_port_dclose(vidcdevsw[unit], + makedev(0, adapter[unit]->va_minor), + flag, mode, td); } static int @@ -462,8 +473,9 @@ fbread(dev_t dev, struct uio *uio, int flag) unit = FB_UNIT(dev); if (vidcdevsw[unit] == NULL) return ENXIO; - return (*vidcdevsw[unit]->d_read)(makedev(0, adapter[unit]->va_minor), - uio, flag); + return dev_port_dread(vidcdevsw[unit], + makedev(0, adapter[unit]->va_minor), + uio, flag); } static int @@ -474,8 +486,9 @@ fbwrite(dev_t dev, struct uio *uio, int flag) unit = FB_UNIT(dev); if (vidcdevsw[unit] == NULL) return ENXIO; - return (*vidcdevsw[unit]->d_write)(makedev(0, adapter[unit]->va_minor), - uio, flag); + return dev_port_dwrite(vidcdevsw[unit], + makedev(0, adapter[unit]->va_minor), + uio, flag); } static int @@ -486,8 +499,9 @@ fbioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td) unit = FB_UNIT(dev); if (vidcdevsw[unit] == NULL) return ENXIO; - return (*vidcdevsw[unit]->d_ioctl)(makedev(0, adapter[unit]->va_minor), - cmd, arg, flag, td); + return dev_port_dioctl(vidcdevsw[unit], + makedev(0, adapter[unit]->va_minor), + cmd, arg, flag, td); } static int @@ -498,8 +512,9 @@ fbmmap(dev_t dev, vm_offset_t offset, int nprot) unit = FB_UNIT(dev); if (vidcdevsw[unit] == NULL) return ENXIO; - return (*vidcdevsw[unit]->d_mmap)(makedev(0, adapter[unit]->va_minor), - offset, nprot); + return (dev_port_dmmap(vidcdevsw[unit], + makedev(0, adapter[unit]->va_minor), + offset, nprot)); } #if experimental diff --git a/sys/dev/video/fb/fbreg.h b/sys/dev/video/fb/fbreg.h index 160dfb8941..7ea5294585 100644 --- a/sys/dev/video/fb/fbreg.h +++ b/sys/dev/video/fb/fbreg.h @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/fb/fbreg.h,v 1.6 1999/12/29 04:35:36 peter Exp $ - * $DragonFly: src/sys/dev/video/fb/fbreg.h,v 1.3 2003/07/21 07:57:40 dillon Exp $ + * $DragonFly: src/sys/dev/video/fb/fbreg.h,v 1.4 2003/07/22 17:03:28 dillon Exp $ */ #ifndef _DEV_FB_FBREG_H_ @@ -171,10 +171,8 @@ int vid_configure(int flags); #ifdef FB_INSTALL_CDEV /* virtual frame buffer driver functions */ -int fb_attach(dev_t dev, video_adapter_t *adp, - struct cdevsw *cdevsw); -int fb_detach(dev_t dev, video_adapter_t *adp, - struct cdevsw *cdevsw); +int fb_attach(dev_t dev, video_adapter_t *adp); +int fb_detach(dev_t dev, video_adapter_t *adp); /* generic frame buffer cdev driver functions */ diff --git a/sys/dev/video/fb/gfb.h b/sys/dev/video/fb/gfb.h index 9208c4bf39..2ed9416e9f 100644 --- a/sys/dev/video/fb/gfb.h +++ b/sys/dev/video/fb/gfb.h @@ -27,7 +27,7 @@ * Copyright (c) 2000 Andrew Miklic * * $FreeBSD: src/sys/dev/fb/gfb.h,v 1.1.2.1 2001/11/01 08:33:14 obrien Exp $ - * $DragonFly: src/sys/dev/video/fb/Attic/gfb.h,v 1.2 2003/06/17 04:28:25 dillon Exp $ + * $DragonFly: src/sys/dev/video/fb/Attic/gfb.h,v 1.3 2003/07/22 17:03:28 dillon Exp $ */ #ifndef _FB_GFB_H_ @@ -166,7 +166,6 @@ typedef struct gfb_softc { u_int8_t rev; /* GFB revision */ int type; int model; - struct cdevsw *cdevsw; dev_t devt; } *gfb_softc_t; diff --git a/sys/dev/video/fb/vgareg.h b/sys/dev/video/fb/vgareg.h index 9c26df889e..c102d35a2a 100644 --- a/sys/dev/video/fb/vgareg.h +++ b/sys/dev/video/fb/vgareg.h @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/fb/vgareg.h,v 1.4 1999/12/29 04:35:37 peter Exp $ - * $DragonFly: src/sys/dev/video/fb/vgareg.h,v 1.3 2003/07/21 07:57:40 dillon Exp $ + * $DragonFly: src/sys/dev/video/fb/vgareg.h,v 1.4 2003/07/22 17:03:28 dillon Exp $ */ #ifndef _DEV_FB_VGAREG_H_ @@ -72,6 +72,7 @@ typedef struct vga_softc { struct video_adapter *adp; #ifdef FB_INSTALL_CDEV genfb_softc_t gensc; + dev_t devt; #endif } vga_softc_t; diff --git a/sys/dev/video/gfb/gfb_pci.c b/sys/dev/video/gfb/gfb_pci.c index 33ef8f0667..acd1c9a36b 100644 --- a/sys/dev/video/gfb/gfb_pci.c +++ b/sys/dev/video/gfb/gfb_pci.c @@ -27,7 +27,7 @@ * Copyright (c) 2000 Andrew Miklic, Andrew Gallatin, and Thomas V. Crimi * * $FreeBSD: src/sys/dev/gfb/gfb_pci.c,v 1.1.2.1 2001/11/01 08:33:15 obrien Exp $ - * $DragonFly: src/sys/dev/video/gfb/Attic/gfb_pci.c,v 1.2 2003/06/17 04:28:26 dillon Exp $ + * $DragonFly: src/sys/dev/video/gfb/Attic/gfb_pci.c,v 1.3 2003/07/22 17:03:29 dillon Exp $ */ #include @@ -205,7 +205,7 @@ pcigfb_attach(device_t dev) sc->adp->va_info.vi_depth, sc->gfbc->ramdac_name); #ifdef FB_INSTALL_CDEV /* attach a virtual frame buffer device */ - error = fb_attach(makedev(0, unit), sc->adp, sc->cdevsw); + error = fb_attach(sc->devt, sc->adp); if(error) goto fail; if(bootverbose) diff --git a/sys/dev/video/tga/tga_pci.c b/sys/dev/video/tga/tga_pci.c index 885fcfc156..4365bb9df8 100644 --- a/sys/dev/video/tga/tga_pci.c +++ b/sys/dev/video/tga/tga_pci.c @@ -27,7 +27,7 @@ * Copyright (c) 2000 Andrew Miklic, Andrew Gallatin, and Thomas V. Crimi * * $FreeBSD: src/sys/dev/tga/tga_pci.c,v 1.1.2.1 2001/11/01 08:33:15 obrien Exp $ - * $DragonFly: src/sys/dev/video/tga/Attic/tga_pci.c,v 1.3 2003/07/21 05:50:37 dillon Exp $ + * $DragonFly: src/sys/dev/video/tga/Attic/tga_pci.c,v 1.4 2003/07/22 17:03:31 dillon Exp $ */ #include @@ -192,8 +192,8 @@ tga_attach(device_t dev) break; } #ifdef FB_INSTALL_CDEV - sc->cdevsw = &tga_cdevsw; - sc->devt = make_dev(sc->cdevsw, unit, 0, 0, 02660, "tga%x", unit); + sc->devt = make_dev(&tga_cdevsw, unit, 0, 0, 02660, "tga%x", unit); + /* XXX fb_attach done too early in pcigfb_attach? */ #endif /*FB_INSTALL_CDEV*/ goto done; fail: diff --git a/sys/emulation/linux/linux_stats.c b/sys/emulation/linux/linux_stats.c index 8199b07031..e8ed350d3d 100644 --- a/sys/emulation/linux/linux_stats.c +++ b/sys/emulation/linux/linux_stats.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/compat/linux/linux_stats.c,v 1.22.2.3 2001/11/05 19:08:23 marcel Exp $ - * $DragonFly: src/sys/emulation/linux/linux_stats.c,v 1.4 2003/06/25 03:55:44 dillon Exp $ + * $DragonFly: src/sys/emulation/linux/linux_stats.c,v 1.5 2003/07/22 17:03:26 dillon Exp $ */ #include @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -52,7 +53,6 @@ static int newstat_copyout(struct stat *buf, void *ubuf) { struct l_newstat tbuf; - struct cdevsw *cdevsw; dev_t dev; tbuf.st_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8); @@ -74,8 +74,7 @@ newstat_copyout(struct stat *buf, void *ubuf) */ if (S_ISCHR(tbuf.st_mode) && (dev = udev2dev(buf->st_rdev, 0)) != NODEV) { - cdevsw = devsw(dev); - if (cdevsw != NULL && (cdevsw->d_flags & D_DISK)) { + if (dev_dport(dev) != NULL && (dev_dflags(dev) & D_DISK)) { tbuf.st_mode &= ~S_IFMT; tbuf.st_mode |= S_IFBLK; diff --git a/sys/i386/i386/autoconf.c b/sys/i386/i386/autoconf.c index 243d463729..2384125ce3 100644 --- a/sys/i386/i386/autoconf.c +++ b/sys/i386/i386/autoconf.c @@ -35,7 +35,7 @@ * * from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91 * $FreeBSD: src/sys/i386/i386/autoconf.c,v 1.146.2.2 2001/06/07 06:05:58 dd Exp $ - * $DragonFly: src/sys/i386/i386/Attic/autoconf.c,v 1.6 2003/07/21 05:50:39 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/autoconf.c,v 1.7 2003/07/22 17:03:32 dillon Exp $ */ /* @@ -69,6 +69,7 @@ #include #include #include +#include #include #include @@ -304,7 +305,7 @@ setroot() } majdev = boot_translate_majdev(B_TYPE(bootdev)); dev = makedev(majdev, 0); - if (devsw(dev) == NULL) + if (dev_dport(dev) == NULL) return; unit = B_UNIT(bootdev); slice = B_SLICE(bootdev); diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c index b53e66d5fc..986cdc5cb5 100644 --- a/sys/kern/kern_conf.c +++ b/sys/kern/kern_conf.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/kern_conf.c,v 1.73.2.3 2003/03/10 02:18:25 imp Exp $ - * $DragonFly: src/sys/kern/kern_conf.c,v 1.3 2003/07/21 05:50:43 dillon Exp $ + * $DragonFly: src/sys/kern/kern_conf.c,v 1.4 2003/07/22 17:03:33 dillon Exp $ */ #include @@ -43,12 +43,11 @@ #include #include #include +#include #include #define cdevsw_ALLOCSTART (NUMCDEVSW/2) -static struct cdevsw *cdevsw[NUMCDEVSW]; - MALLOC_DEFINE(M_DEVT, "dev_t", "dev_t storage"); /* @@ -70,87 +69,6 @@ static LIST_HEAD(, specinfo) dev_free; static int free_devt; SYSCTL_INT(_debug, OID_AUTO, free_devt, CTLFLAG_RW, &free_devt, 0, ""); -struct cdevsw * -devsw(dev_t dev) -{ - if (dev->si_devsw) - return (dev->si_devsw); - return(cdevsw[major(dev)]); -} - -static void -compile_devsw(struct cdevsw *devsw) -{ - static lwkt_port devsw_compat_port; - - /* YYY init devsw_compat_port */ - - if (devsw->d_open == NULL) - devsw->d_open = noopen; - if (devsw->d_close == NULL) - devsw->d_close = noclose; - if (devsw->d_read == NULL) - devsw->d_read = noread; - if (devsw->d_write == NULL) - devsw->d_write = nowrite; - if (devsw->d_ioctl == NULL) - devsw->d_ioctl = noioctl; - if (devsw->d_poll == NULL) - devsw->d_poll = nopoll; - if (devsw->d_mmap == NULL) - devsw->d_mmap = nommap; - if (devsw->d_strategy == NULL) - devsw->d_strategy = nostrategy; - if (devsw->d_dump == NULL) - devsw->d_dump = nodump; - if (devsw->d_psize == NULL) - devsw->d_psize = nopsize; - if (devsw->d_kqfilter == NULL) - devsw->d_kqfilter = nokqfilter; - if (devsw->d_port == NULL) - devsw->d_port = &devsw_compat_port; -} - -/* - * Add a cdevsw entry - */ - -int -cdevsw_add(struct cdevsw *newentry) -{ - compile_devsw(newentry); - if (newentry->d_maj < 0 || newentry->d_maj >= NUMCDEVSW) { - printf("%s: ERROR: driver has bogus cdevsw->d_maj = %d\n", - newentry->d_name, newentry->d_maj); - return (EINVAL); - } - if (cdevsw[newentry->d_maj]) { - printf("WARNING: \"%s\" is usurping \"%s\"'s cdevsw[]\n", - newentry->d_name, cdevsw[newentry->d_maj]->d_name); - } - - cdevsw[newentry->d_maj] = newentry; - return (0); -} - -/* - * Remove a cdevsw entry - */ - -int -cdevsw_remove(struct cdevsw *oldentry) -{ - if (oldentry->d_maj < 0 || oldentry->d_maj >= NUMCDEVSW) { - printf("%s: ERROR: driver has bogus cdevsw->d_maj = %d\n", - oldentry->d_name, oldentry->d_maj); - return EINVAL; - } - - cdevsw[oldentry->d_maj] = NULL; - - return 0; -} - /* * dev_t and u_dev_t primitives */ @@ -309,21 +227,25 @@ destroy_dev(dev_t dev) const char * devtoname(dev_t dev) { - char *p; int mynor; + int len; + char *p; + const char *dname; if (dev->si_name[0] == '#' || dev->si_name[0] == '\0') { p = dev->si_name; - if (devsw(dev)) - sprintf(p, "#%s/", devsw(dev)->d_name); + len = sizeof(dev->si_name); + if ((dname = dev_dname(dev)) != NULL) + snprintf(p, len, "#%s/", dname); else - sprintf(p, "#%d/", major(dev)); + snprintf(p, len, "#%d/", major(dev)); + len -= strlen(p); p += strlen(p); mynor = minor(dev); if (mynor < 0 || mynor > 255) - sprintf(p, "%#x", (u_int)mynor); + snprintf(p, len, "%#x", (u_int)mynor); else - sprintf(p, "%d", mynor); + snprintf(p, len, "%d", mynor); } return (dev->si_name); } diff --git a/sys/kern/kern_device.c b/sys/kern/kern_device.c new file mode 100644 index 0000000000..e7e8e444ee --- /dev/null +++ b/sys/kern/kern_device.c @@ -0,0 +1,678 @@ +/* + * Copyright (c) 2003 Matthew Dillon All rights reserved. + * cdevsw from kern/kern_conf.c Copyright (c) 1995 Terrence R. Lambert + * cdevsw from kern/kern_conf.c Copyright (c) 1995 Julian R. Elishcer, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $DragonFly: src/sys/kern/kern_device.c,v 1.1 2003/07/22 17:03:33 dillon Exp $ + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct cdevsw *cdevsw[NUMCDEVSW]; +static struct lwkt_port *cdevport[NUMCDEVSW]; + +static int cdevsw_putport(lwkt_port_t port, lwkt_msg_t msg); + +/* + * Initialize a message port to serve as the default message-handling port + * for device operations. This message port provides compatibility with + * traditional cdevsw dispatch functions. There are two primary modes: + * + * mp_td is NULL: The d_autoq mask is ignored and all messages are translated + * into directly, synchronous cdevsw calls. + * + * mp_td not NULL: The d_autoq mask is used to determine which messages should + * be queued and which should be handled synchronously. + * + * Don't worry too much about optimizing this code, the critical devices + * will implement their own port messaging functions directly. + */ +static void +init_default_cdevsw_port(lwkt_port_t port) +{ + lwkt_init_port(port, NULL); + port->mp_beginmsg = cdevsw_putport; +} + +static +int +cdevsw_putport(lwkt_port_t port, lwkt_msg_t lmsg) +{ + cdevallmsg_t msg = (cdevallmsg_t)lmsg; + struct cdevsw *csw = msg->am_msg.csw; + int error; + + /* + * If queueable then officially queue the message + */ + if (port->mp_td) { + int mask = (1 << (msg->am_lmsg.ms_cmd & MSG_SUBCMD_MASK)); + if (csw->d_autoq & mask) + return(lwkt_putport(port, &msg->am_lmsg)); + } + + /* + * Run the device switch function synchronously in the context of the + * caller and return a synchronous error code (anything not EINPROGRESS). + */ + switch(msg->am_lmsg.ms_cmd) { + case CDEV_CMD_OPEN: + error = csw->old_open( + msg->am_open.msg.dev, + msg->am_open.oflags, + msg->am_open.devtype, + msg->am_open.td); + break; + case CDEV_CMD_CLOSE: + error = csw->old_close( + msg->am_close.msg.dev, + msg->am_close.fflag, + msg->am_close.devtype, + msg->am_close.td); + break; + case CDEV_CMD_STRATEGY: + csw->old_strategy(msg->am_strategy.bp); + error = 0; + break; + case CDEV_CMD_IOCTL: + error = csw->old_ioctl( + msg->am_ioctl.msg.dev, + msg->am_ioctl.cmd, + msg->am_ioctl.data, + msg->am_ioctl.fflag, + msg->am_ioctl.td); + break; + case CDEV_CMD_DUMP: + error = csw->old_dump(msg->am_ioctl.msg.dev); + break; + case CDEV_CMD_PSIZE: + msg->am_psize.result = csw->old_psize(msg->am_psize.msg.dev); + error = 0; /* XXX */ + break; + case CDEV_CMD_READ: + error = csw->old_read( + msg->am_read.msg.dev, + msg->am_read.uio, + msg->am_read.ioflag); + break; + case CDEV_CMD_WRITE: + error = csw->old_write( + msg->am_read.msg.dev, + msg->am_read.uio, + msg->am_read.ioflag); + break; + case CDEV_CMD_POLL: + msg->am_poll.events = csw->old_poll( + msg->am_poll.msg.dev, + msg->am_poll.events, + msg->am_poll.td); + error = 0; + break; + case CDEV_CMD_KQFILTER: + msg->am_kqfilter.result = csw->old_kqfilter( + msg->am_kqfilter.msg.dev, + msg->am_kqfilter.kn); + error = 0; + break; + case CDEV_CMD_MMAP: + msg->am_mmap.result = csw->old_mmap( + msg->am_mmap.msg.dev, + msg->am_mmap.offset, + msg->am_mmap.nprot); + error = 0; /* XXX */ + break; + default: + error = ENOSYS; + break; + } + KKASSERT(error != EINPROGRESS); + return(error); +} + +/* + * These device dispatch functions provide convenient entry points for + * any code wishing to make a dev call. + * + * YYY we ought to be able to optimize the port lookup by caching it in + * the dev_t structure itself. + */ +static __inline +struct cdevsw * +_devsw(dev_t dev) +{ + if (dev->si_devsw) + return (dev->si_devsw); + return(cdevsw[major(dev)]); +} + +static __inline +lwkt_port_t +_init_cdevmsg(dev_t dev, cdevmsg_t msg, int cmd) +{ + struct cdevsw *csw; + + lwkt_initmsg(&msg->msg, cmd); + msg->dev = dev; + msg->csw = csw = _devsw(dev); + if (csw != NULL) { /* YYY too hackish */ + KKASSERT(csw->d_port); /* YYY too hackish */ + if (cdevport[major(dev)]) /* YYY too hackish */ + return(cdevport[major(dev)]); + return(csw->d_port); + } + return(NULL); +} + +int +dev_dopen(dev_t dev, int oflags, int devtype, thread_t td) +{ + struct cdevmsg_open msg; + lwkt_port_t port; + + port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_OPEN); + if (port == NULL) + return(ENXIO); + msg.oflags = oflags; + msg.devtype = devtype; + msg.td = td; + return(lwkt_domsg(port, &msg.msg.msg)); +} + +int +dev_dclose(dev_t dev, int fflag, int devtype, thread_t td) +{ + struct cdevmsg_close msg; + lwkt_port_t port; + + port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_CLOSE); + if (port == NULL) + return(ENXIO); + msg.fflag = fflag; + msg.devtype = devtype; + msg.td = td; + return(lwkt_domsg(port, &msg.msg.msg)); +} + +void +dev_dstrategy(dev_t dev, struct buf *bp) +{ + struct cdevmsg_strategy msg; + lwkt_port_t port; + + port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_STRATEGY); + KKASSERT(port); /* 'nostrategy' function is NULL YYY */ + msg.bp = bp; + lwkt_domsg(port, &msg.msg.msg); +} + +int +dev_dioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, thread_t td) +{ + struct cdevmsg_ioctl msg; + lwkt_port_t port; + + port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_IOCTL); + if (port == NULL) + return(ENXIO); + msg.cmd = cmd; + msg.data = data; + msg.fflag = fflag; + msg.td = td; + return(lwkt_domsg(port, &msg.msg.msg)); +} + +int +dev_ddump(dev_t dev) +{ + struct cdevmsg_dump msg; + lwkt_port_t port; + + port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_DUMP); + if (port == NULL) + return(ENXIO); + return(lwkt_domsg(port, &msg.msg.msg)); +} + +int +dev_dpsize(dev_t dev) +{ + struct cdevmsg_psize msg; + lwkt_port_t port; + int error; + + port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_PSIZE); + if (port == NULL) + return(-1); + error = lwkt_domsg(port, &msg.msg.msg); + if (error == 0) + return(msg.result); + return(-1); +} + +int +dev_dread(dev_t dev, struct uio *uio, int ioflag) +{ + struct cdevmsg_read msg; + lwkt_port_t port; + + port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_READ); + if (port == NULL) + return(ENXIO); + msg.uio = uio; + msg.ioflag = ioflag; + return(lwkt_domsg(port, &msg.msg.msg)); +} + +int +dev_dwrite(dev_t dev, struct uio *uio, int ioflag) +{ + struct cdevmsg_write msg; + lwkt_port_t port; + + port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_WRITE); + if (port == NULL) + return(ENXIO); + msg.uio = uio; + msg.ioflag = ioflag; + return(lwkt_domsg(port, &msg.msg.msg)); +} + +int +dev_dpoll(dev_t dev, int events, thread_t td) +{ + struct cdevmsg_poll msg; + lwkt_port_t port; + int error; + + port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_POLL); + if (port == NULL) + return(ENXIO); + msg.events = events; + msg.td = td; + error = lwkt_domsg(port, &msg.msg.msg); + if (error == 0) + return(msg.events); + return(seltrue(dev, msg.events, td)); +} + +int +dev_dkqfilter(dev_t dev, struct knote *kn) +{ + struct cdevmsg_kqfilter msg; + lwkt_port_t port; + int error; + + port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_KQFILTER); + if (port == NULL) + return(ENXIO); + msg.kn = kn; + error = lwkt_domsg(port, &msg.msg.msg); + if (error == 0) + return(msg.result); + return(ENODEV); +} + +int +dev_dmmap(dev_t dev, vm_offset_t offset, int nprot) +{ + struct cdevmsg_mmap msg; + lwkt_port_t port; + int error; + + port = _init_cdevmsg(dev, &msg.msg, CDEV_CMD_MMAP); + if (port == NULL) + return(-1); + msg.offset = offset; + msg.nprot = nprot; + error = lwkt_domsg(port, &msg.msg.msg); + if (error == 0) + return(msg.result); + return(-1); +} + +int +dev_port_dopen(lwkt_port_t port, dev_t dev, int oflags, int devtype, thread_t td) +{ + struct cdevmsg_open msg; + + _init_cdevmsg(dev, &msg.msg, CDEV_CMD_OPEN); + if (port == NULL) + return(ENXIO); + msg.oflags = oflags; + msg.devtype = devtype; + msg.td = td; + return(lwkt_domsg(port, &msg.msg.msg)); +} + +int +dev_port_dclose(lwkt_port_t port, dev_t dev, int fflag, int devtype, thread_t td) +{ + struct cdevmsg_close msg; + + _init_cdevmsg(dev, &msg.msg, CDEV_CMD_CLOSE); + if (port == NULL) + return(ENXIO); + msg.fflag = fflag; + msg.devtype = devtype; + msg.td = td; + return(lwkt_domsg(port, &msg.msg.msg)); +} + +void +dev_port_dstrategy(lwkt_port_t port, dev_t dev, struct buf *bp) +{ + struct cdevmsg_strategy msg; + + _init_cdevmsg(dev, &msg.msg, CDEV_CMD_STRATEGY); + KKASSERT(port); /* 'nostrategy' function is NULL YYY */ + msg.bp = bp; + lwkt_domsg(port, &msg.msg.msg); +} + +int +dev_port_dioctl(lwkt_port_t port, dev_t dev, u_long cmd, caddr_t data, int fflag, thread_t td) +{ + struct cdevmsg_ioctl msg; + + _init_cdevmsg(dev, &msg.msg, CDEV_CMD_IOCTL); + if (port == NULL) + return(ENXIO); + msg.cmd = cmd; + msg.data = data; + msg.fflag = fflag; + msg.td = td; + return(lwkt_domsg(port, &msg.msg.msg)); +} + +int +dev_port_ddump(lwkt_port_t port, dev_t dev) +{ + struct cdevmsg_dump msg; + + _init_cdevmsg(dev, &msg.msg, CDEV_CMD_DUMP); + if (port == NULL) + return(ENXIO); + return(lwkt_domsg(port, &msg.msg.msg)); +} + +int +dev_port_dpsize(lwkt_port_t port, dev_t dev) +{ + struct cdevmsg_psize msg; + int error; + + _init_cdevmsg(dev, &msg.msg, CDEV_CMD_PSIZE); + if (port == NULL) + return(-1); + error = lwkt_domsg(port, &msg.msg.msg); + if (error == 0) + return(msg.result); + return(-1); +} + +int +dev_port_dread(lwkt_port_t port, dev_t dev, struct uio *uio, int ioflag) +{ + struct cdevmsg_read msg; + + _init_cdevmsg(dev, &msg.msg, CDEV_CMD_READ); + if (port == NULL) + return(ENXIO); + msg.uio = uio; + msg.ioflag = ioflag; + return(lwkt_domsg(port, &msg.msg.msg)); +} + +int +dev_port_dwrite(lwkt_port_t port, dev_t dev, struct uio *uio, int ioflag) +{ + struct cdevmsg_write msg; + + _init_cdevmsg(dev, &msg.msg, CDEV_CMD_WRITE); + if (port == NULL) + return(ENXIO); + msg.uio = uio; + msg.ioflag = ioflag; + return(lwkt_domsg(port, &msg.msg.msg)); +} + +int +dev_port_dpoll(lwkt_port_t port, dev_t dev, int events, thread_t td) +{ + struct cdevmsg_poll msg; + int error; + + _init_cdevmsg(dev, &msg.msg, CDEV_CMD_POLL); + if (port == NULL) + return(ENXIO); + msg.events = events; + msg.td = td; + error = lwkt_domsg(port, &msg.msg.msg); + if (error == 0) + return(msg.events); + return(seltrue(dev, msg.events, td)); +} + +int +dev_port_dkqfilter(lwkt_port_t port, dev_t dev, struct knote *kn) +{ + struct cdevmsg_kqfilter msg; + int error; + + _init_cdevmsg(dev, &msg.msg, CDEV_CMD_KQFILTER); + if (port == NULL) + return(ENXIO); + msg.kn = kn; + error = lwkt_domsg(port, &msg.msg.msg); + if (error == 0) + return(msg.result); + return(ENODEV); +} + +int +dev_port_dmmap(lwkt_port_t port, dev_t dev, vm_offset_t offset, int nprot) +{ + struct cdevmsg_mmap msg; + int error; + + _init_cdevmsg(dev, &msg.msg, CDEV_CMD_MMAP); + if (port == NULL) + return(-1); + msg.offset = offset; + msg.nprot = nprot; + error = lwkt_domsg(port, &msg.msg.msg); + if (error == 0) + return(msg.result); + return(-1); +} + +const char * +dev_dname(dev_t dev) +{ + struct cdevsw *csw; + + if ((csw = _devsw(dev)) != NULL) + return(csw->d_name); + return(NULL); +} + +int +dev_dflags(dev_t dev) +{ + struct cdevsw *csw; + + if ((csw = _devsw(dev)) != NULL) + return(csw->d_flags); + return(NULL); +} + +int +dev_dmaj(dev_t dev) +{ + struct cdevsw *csw; + + if ((csw = _devsw(dev)) != NULL) + return(csw->d_maj); + return(NULL); +} + +lwkt_port_t +dev_dport(dev_t dev) +{ + struct cdevsw *csw; + + if ((csw = _devsw(dev)) != NULL) { + if (cdevport[major(dev)]) /* YYY too hackish */ + return(cdevport[major(dev)]); + return(csw->d_port); + } + return(NULL); +} + +#if 0 +/* + * cdevsw[] array functions, moved from kern/kern_conf.c + */ +struct cdevsw * +devsw(dev_t dev) +{ + return(_devsw(dev)); +} +#endif + +/* + * Convert a cdevsw template into the real thing, filling in fields the + * device left empty with appropriate defaults. + */ +void +compile_devsw(struct cdevsw *devsw) +{ + static lwkt_port devsw_compat_port; + + if (devsw_compat_port.mp_beginmsg == NULL) + init_default_cdevsw_port(&devsw_compat_port); + + if (devsw->old_open == NULL) + devsw->old_open = noopen; + if (devsw->old_close == NULL) + devsw->old_close = noclose; + if (devsw->old_read == NULL) + devsw->old_read = noread; + if (devsw->old_write == NULL) + devsw->old_write = nowrite; + if (devsw->old_ioctl == NULL) + devsw->old_ioctl = noioctl; + if (devsw->old_poll == NULL) + devsw->old_poll = nopoll; + if (devsw->old_mmap == NULL) + devsw->old_mmap = nommap; + if (devsw->old_strategy == NULL) + devsw->old_strategy = nostrategy; + if (devsw->old_dump == NULL) + devsw->old_dump = nodump; + if (devsw->old_psize == NULL) + devsw->old_psize = nopsize; + if (devsw->old_kqfilter == NULL) + devsw->old_kqfilter = nokqfilter; + + if (devsw->d_port == NULL) + devsw->d_port = &devsw_compat_port; +} + +/* + * Add a cdevsw entry + */ +int +cdevsw_add(struct cdevsw *newentry) +{ + compile_devsw(newentry); + if (newentry->d_maj < 0 || newentry->d_maj >= NUMCDEVSW) { + printf("%s: ERROR: driver has bogus cdevsw->d_maj = %d\n", + newentry->d_name, newentry->d_maj); + return (EINVAL); + } + if (cdevsw[newentry->d_maj]) { + printf("WARNING: \"%s\" is usurping \"%s\"'s cdevsw[]\n", + newentry->d_name, cdevsw[newentry->d_maj]->d_name); + } + cdevsw[newentry->d_maj] = newentry; + return (0); +} + +/* + * Add a cdevsw entry and override the port. + */ +lwkt_port_t +cdevsw_add_override(struct cdevsw *newentry, lwkt_port_t port) +{ + int error; + + if ((error = cdevsw_add(newentry)) == 0) + cdevport[newentry->d_maj] = port; + return(newentry->d_port); +} + +lwkt_port_t +cdevsw_dev_override(dev_t dev, lwkt_port_t port) +{ + struct cdevsw *csw; + + KKASSERT(major(dev) >= 0 && major(dev) < NUMCDEVSW); + if ((csw = _devsw(dev)) != NULL) { + cdevport[major(dev)] = port; + return(csw->d_port); + } + return(NULL); +} + +/* + * Remove a cdevsw entry + */ +int +cdevsw_remove(struct cdevsw *oldentry) +{ + if (oldentry->d_maj < 0 || oldentry->d_maj >= NUMCDEVSW) { + printf("%s: ERROR: driver has bogus cdevsw->d_maj = %d\n", + oldentry->d_name, oldentry->d_maj); + return EINVAL; + } + cdevsw[oldentry->d_maj] = NULL; + cdevport[oldentry->d_maj] = NULL; + return 0; +} + diff --git a/sys/kern/kern_physio.c b/sys/kern/kern_physio.c index 61553571b6..73a1884f3c 100644 --- a/sys/kern/kern_physio.c +++ b/sys/kern/kern_physio.c @@ -17,7 +17,7 @@ * are met. * * $FreeBSD: src/sys/kern/kern_physio.c,v 1.46.2.3 2003/05/29 06:15:35 alc Exp $ - * $DragonFly: src/sys/kern/kern_physio.c,v 1.4 2003/07/19 21:14:38 dillon Exp $ + * $DragonFly: src/sys/kern/kern_physio.c,v 1.5 2003/07/22 17:03:33 dillon Exp $ */ #include @@ -26,6 +26,7 @@ #include #include #include +#include #include #include diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c index 30e02cfd66..f02f606897 100644 --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -37,7 +37,7 @@ * * @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/kern_shutdown.c,v 1.72.2.12 2002/02/21 19:15:10 dillon Exp $ - * $DragonFly: src/sys/kern/kern_shutdown.c,v 1.8 2003/07/04 00:32:30 dillon Exp $ + * $DragonFly: src/sys/kern/kern_shutdown.c,v 1.9 2003/07/22 17:03:33 dillon Exp $ */ #include "opt_ddb.h" @@ -61,6 +61,7 @@ #include #include #include +#include #include #include @@ -416,13 +417,9 @@ setdumpdev(dev) dumpdev = dev; return (0); } - if (devsw(dev) == NULL) - return (ENXIO); /* XXX is this right? */ - if (devsw(dev)->d_psize == NULL) - return (ENXIO); /* XXX should be ENODEV ? */ - psize = devsw(dev)->d_psize(dev); + psize = dev_dpsize(dev); if (psize == -1) - return (ENXIO); /* XXX should be ENODEV ? */ + return (ENXIO); /* * XXX should clean up checking in dumpsys() to be more like this. */ @@ -492,20 +489,17 @@ dumpsys(void) return; if (dumpdev == NODEV) return; - if (!(devsw(dumpdev))) - return; - if (!(devsw(dumpdev)->d_dump)) - return; dumpsize = Maxmem; printf("\ndumping to dev %s, offset %ld\n", devtoname(dumpdev), dumplo); printf("dump "); - error = (*devsw(dumpdev)->d_dump)(dumpdev); + error = dev_ddump(dumpdev); if (error == 0) { printf("succeeded\n"); return; } printf("failed, reason: "); switch (error) { + case ENOSYS: case ENODEV: printf("device doesn't support a dump routine\n"); break; diff --git a/sys/kern/lwkt_msgport.c b/sys/kern/lwkt_msgport.c index 3e22b804f7..32bc92dec3 100644 --- a/sys/kern/lwkt_msgport.c +++ b/sys/kern/lwkt_msgport.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/lwkt_msgport.c,v 1.1 2003/07/20 01:37:22 dillon Exp $ + * $DragonFly: src/sys/kern/lwkt_msgport.c,v 1.2 2003/07/22 17:03:33 dillon Exp $ */ #include @@ -86,6 +86,7 @@ lwkt_sendmsg(lwkt_port_t port, lwkt_msg_t msg) msg->ms_flags |= MSGF_ASYNC; msg->ms_flags &= ~(MSGF_REPLY | MSGF_QUEUED); msg->ms_reply_port = &curthread->td_msgport; + msg->ms_abortreq = 0; if ((error = lwkt_beginmsg(port, msg)) != EINPROGRESS) { lwkt_replymsg(msg, error); } @@ -114,6 +115,7 @@ lwkt_domsg(lwkt_port_t port, lwkt_msg_t msg) msg->ms_flags &= ~(MSGF_ASYNC | MSGF_REPLY | MSGF_QUEUED); msg->ms_reply_port = &curthread->td_msgport; + msg->ms_abortreq = 0; if ((error = lwkt_beginmsg(port, msg)) == EINPROGRESS) { error = lwkt_waitmsg(msg); } @@ -282,7 +284,9 @@ lwkt_putport_remote(lwkt_msg_t msg) int lwkt_putport(lwkt_port_t port, lwkt_msg_t msg) { + crit_enter(); _lwkt_putport(port, msg); + crit_exit(); return(EINPROGRESS); } @@ -337,7 +341,9 @@ void lwkt_abortport(lwkt_port_t port, lwkt_msg_t msg) { msg->ms_abortreq = 1; + crit_enter(); _lwkt_abortport(port); + crit_exit(); } /* diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 17a1cb71a8..fb5d752174 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -7,7 +7,7 @@ * ---------------------------------------------------------------------------- * * $FreeBSD: src/sys/kern/subr_disk.c,v 1.20.2.6 2001/10/05 07:14:57 peter Exp $ - * $DragonFly: src/sys/kern/subr_disk.c,v 1.4 2003/07/19 21:14:38 dillon Exp $ + * $DragonFly: src/sys/kern/subr_disk.c,v 1.5 2003/07/22 17:03:33 dillon Exp $ * */ @@ -22,6 +22,8 @@ #include #include #include +#include +#include static MALLOC_DEFINE(M_DISK, "disk", "disk data"); @@ -30,6 +32,7 @@ static d_open_t diskopen; static d_close_t diskclose; static d_ioctl_t diskioctl; static d_psize_t diskpsize; +static int disk_putport(lwkt_port_t port, lwkt_msg_t msg); static LIST_HEAD(, disk) disklist = LIST_HEAD_INITIALIZER(&disklist); @@ -44,37 +47,54 @@ inherit_raw(dev_t pdev, dev_t dev) dev->si_bsize_best = pdev->si_bsize_best; } +/* + * Create a slice and unit managed disk. The underlying raw disk device + * is specified by cdevsw. We create the device as a managed device by + * first creating it normally then overriding the message port with our + * own frontend (which will be responsible for assigning pblkno). + */ dev_t -disk_create(int unit, struct disk *dp, int flags, struct cdevsw *cdevsw, struct cdevsw *proto) +disk_create(int unit, struct disk *dp, int flags, struct cdevsw *cdevsw) { dev_t dev; bzero(dp, sizeof(*dp)); + lwkt_init_port(&dp->d_port, NULL); /* intercept port */ + dp->d_port.mp_beginmsg = disk_putport; - dev = makedev(cdevsw->d_maj, 0); - if (!devsw(dev)) { - *proto = *cdevsw; - proto->d_open = diskopen; - proto->d_close = diskclose; - proto->d_ioctl = diskioctl; - proto->d_strategy = diskstrategy; - proto->d_psize = diskpsize; - cdevsw_add(proto); - } + dev = makedev(cdevsw->d_maj, 0); /* base device */ + dev->si_disk = dp; + /* forwarding port */ + dp->d_fwdport = cdevsw_add_override(cdevsw, &dp->d_port); if (bootverbose) printf("Creating DISK %s%d\n", cdevsw->d_name, unit); - dev = make_dev(proto, dkmakeminor(unit, WHOLE_DISK_SLICE, RAW_PART), - UID_ROOT, GID_OPERATOR, 0640, "%s%d", cdevsw->d_name, unit); + /* + * The whole disk placemarker holds the disk structure. + */ + dev = make_dev(cdevsw, dkmakeminor(unit, WHOLE_DISK_SLICE, RAW_PART), + UID_ROOT, GID_OPERATOR, 0640, "%s%d", cdevsw->d_name, unit); dev->si_disk = dp; dp->d_dev = dev; dp->d_dsflags = flags; - dp->d_devsw = cdevsw; LIST_INSERT_HEAD(&disklist, dp, d_list); return (dev); } +void +disk_destroy(struct disk *disk) +{ + dev_t dev = disk->d_dev; + + LIST_REMOVE(disk, d_list); + bzero(disk, sizeof(*disk)); + dev->si_disk = NULL; + destroy_dev(dev); + /* YYY remove cdevsw entries? */ + return; +} + int disk_dumpcheck(dev_t dev, u_int *count, u_int *blkno, u_int *secsize) { @@ -109,16 +129,6 @@ disk_invalidate (struct disk *disk) dsgone(&disk->d_slice); } -void -disk_destroy(dev_t dev) -{ - LIST_REMOVE(dev->si_disk, d_list); - bzero(dev->si_disk, sizeof(*dev->si_disk)); - dev->si_disk = NULL; - destroy_dev(dev); - return; -} - struct disk * disk_enumerate(struct disk *disk) { @@ -157,8 +167,53 @@ SYSCTL_PROC(_kern, OID_AUTO, disks, CTLTYPE_STRING | CTLFLAG_RD, 0, NULL, sysctl_disks, "A", "names of available disks"); /* - * The cdevsw functions + * The port intercept functions */ +static +int +disk_putport(lwkt_port_t port, lwkt_msg_t lmsg) +{ + struct disk *disk = (struct disk *)port; + cdevallmsg_t msg = (cdevallmsg_t)lmsg; + int error; + + switch(msg->am_lmsg.ms_cmd) { + case CDEV_CMD_OPEN: + error = diskopen( + msg->am_open.msg.dev, + msg->am_open.oflags, + msg->am_open.devtype, + msg->am_open.td); + break; + case CDEV_CMD_CLOSE: + error = diskclose( + msg->am_close.msg.dev, + msg->am_close.fflag, + msg->am_close.devtype, + msg->am_close.td); + break; + case CDEV_CMD_IOCTL: + error = diskioctl( + msg->am_ioctl.msg.dev, + msg->am_ioctl.cmd, + msg->am_ioctl.data, + msg->am_ioctl.fflag, + msg->am_ioctl.td); + break; + case CDEV_CMD_STRATEGY: + diskstrategy(msg->am_strategy.bp); + error = 0; + break; + case CDEV_CMD_PSIZE: + msg->am_psize.result = diskpsize(msg->am_psize.msg.dev); + error = 0; /* XXX */ + break; + default: + error = lwkt_forwardmsg(disk->d_fwdport, &msg->am_lmsg); + break; + } + return(error); +} static int diskopen(dev_t dev, int oflags, int devtype, struct thread *td) @@ -171,7 +226,7 @@ diskopen(dev_t dev, int oflags, int devtype, struct thread *td) pdev = dkmodpart(dkmodslice(dev, WHOLE_DISK_SLICE), RAW_PART); dp = pdev->si_disk; - if (!dp) + if (dp == NULL) return (ENXIO); while (dp->d_flags & DISKFLAG_LOCK) { @@ -185,7 +240,7 @@ diskopen(dev_t dev, int oflags, int devtype, struct thread *td) if (!dsisopen(dp->d_slice)) { if (!pdev->si_iosize_max) pdev->si_iosize_max = dev->si_iosize_max; - error = dp->d_devsw->d_open(pdev, oflags, devtype, td); + error = dev_port_dopen(dp->d_fwdport, pdev, oflags, devtype, td); } /* Inherit properties from the whole/raw dev_t */ @@ -197,7 +252,7 @@ diskopen(dev_t dev, int oflags, int devtype, struct thread *td) error = dsopen(dev, devtype, dp->d_dsflags, &dp->d_slice, &dp->d_label); if (!dsisopen(dp->d_slice)) - dp->d_devsw->d_close(pdev, oflags, devtype, td); + dev_port_dclose(dp->d_fwdport, pdev, oflags, devtype, td); out: dp->d_flags &= ~DISKFLAG_LOCK; if (dp->d_flags & DISKFLAG_WANTED) { @@ -222,7 +277,7 @@ diskclose(dev_t dev, int fflag, int devtype, struct thread *td) return (ENXIO); dsclose(dev, devtype, dp->d_slice); if (!dsisopen(dp->d_slice)) - error = dp->d_devsw->d_close(dp->d_dev, fflag, devtype, td); + error = dev_port_dclose(dp->d_fwdport, pdev, fflag, devtype, td); return (error); } @@ -248,12 +303,13 @@ diskstrategy(struct buf *bp) biodone(bp); return; } - - dp->d_devsw->d_strategy(bp); - return; - + dev_port_dstrategy(dp->d_fwdport, dp->d_dev, bp); } +/* + * note: when forwarding the ioctl we use the original device rather then + * the whole disk slice. + */ static int diskioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td) { @@ -267,7 +323,7 @@ diskioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td) return (ENXIO); error = dsioctl(dev, cmd, data, fflag, &dp->d_slice); if (error == ENOIOCTL) - error = dp->d_devsw->d_ioctl(dev, cmd, data, fflag, td); + error = dev_port_dioctl(dp->d_fwdport, dev, cmd, data, fflag, td); return (error); } diff --git a/sys/kern/subr_diskmbr.c b/sys/kern/subr_diskmbr.c index 652d0d968a..b6142c2a6c 100644 --- a/sys/kern/subr_diskmbr.c +++ b/sys/kern/subr_diskmbr.c @@ -36,7 +36,7 @@ * from: @(#)ufs_disksubr.c 7.16 (Berkeley) 5/4/91 * from: ufs_disksubr.c,v 1.8 1994/06/07 01:21:39 phk Exp $ * $FreeBSD: src/sys/kern/subr_diskmbr.c,v 1.45 2000/01/28 10:22:07 bde Exp $ - * $DragonFly: src/sys/kern/subr_diskmbr.c,v 1.2 2003/06/17 04:28:41 dillon Exp $ + * $DragonFly: src/sys/kern/subr_diskmbr.c,v 1.3 2003/07/22 17:03:33 dillon Exp $ */ #include @@ -54,6 +54,7 @@ #include #include #include +#include #define TRACE(str) do { if (dsi_debug) printf str; } while (0) diff --git a/sys/kern/subr_diskslice.c b/sys/kern/subr_diskslice.c index a83b6babfa..273544b40a 100644 --- a/sys/kern/subr_diskslice.c +++ b/sys/kern/subr_diskslice.c @@ -44,7 +44,7 @@ * from: @(#)ufs_disksubr.c 7.16 (Berkeley) 5/4/91 * from: ufs_disksubr.c,v 1.8 1994/06/07 01:21:39 phk Exp $ * $FreeBSD: src/sys/kern/subr_diskslice.c,v 1.82.2.6 2001/07/24 09:49:41 dd Exp $ - * $DragonFly: src/sys/kern/subr_diskslice.c,v 1.3 2003/06/23 17:55:41 dillon Exp $ + * $DragonFly: src/sys/kern/subr_diskslice.c,v 1.4 2003/07/22 17:03:33 dillon Exp $ */ #include @@ -58,6 +58,7 @@ #include #include #include +#include #include @@ -625,7 +626,7 @@ dsname(dev, unit, slice, part, partname) static char name[32]; const char *dname; - dname = devsw(dev)->d_name; + dname = dev_dname(dev); if (strlen(dname) > 16) dname = "nametoolong"; snprintf(name, sizeof(name), "%s%d", dname, unit); @@ -825,9 +826,9 @@ dssize(dev, sspp) ssp = *sspp; if (ssp == NULL || slice >= ssp->dss_nslices || !(ssp->dss_slices[slice].ds_openmask & (1 << part))) { - if (devsw(dev)->d_open(dev, FREAD, S_IFCHR, NULL) != 0) + if (dev_dopen(dev, FREAD, S_IFCHR, NULL) != 0) return (-1); - devsw(dev)->d_close(dev, FREAD, S_IFCHR, NULL); + dev_dclose(dev, FREAD, S_IFCHR, NULL); ssp = *sspp; } lp = ssp->dss_slices[slice].ds_label; diff --git a/sys/kern/tty_cons.c b/sys/kern/tty_cons.c index eee0728b06..421dcabecf 100644 --- a/sys/kern/tty_cons.c +++ b/sys/kern/tty_cons.c @@ -37,7 +37,7 @@ * * from: @(#)cons.c 7.2 (Berkeley) 5/9/91 * $FreeBSD: src/sys/kern/tty_cons.c,v 1.81.2.4 2001/12/17 18:44:41 guido Exp $ - * $DragonFly: src/sys/kern/tty_cons.c,v 1.5 2003/07/21 05:50:43 dillon Exp $ + * $DragonFly: src/sys/kern/tty_cons.c,v 1.6 2003/07/22 17:03:33 dillon Exp $ */ #include "opt_ddb.h" @@ -52,6 +52,9 @@ #include #include #include +#include +#include +#include #include @@ -64,6 +67,7 @@ static d_write_t cnwrite; static d_ioctl_t cnioctl; static d_poll_t cnpoll; static d_kqfilter_t cnkqfilter; +static int console_putport(lwkt_port_t port, lwkt_msg_t lmsg); #define CDEV_MAJOR 0 static struct cdevsw cn_cdevsw = { @@ -102,13 +106,15 @@ static u_char cn_is_open; /* nonzero if logical console is open */ static int openmode, openflag; /* how /dev/console was openned */ static dev_t cn_devfsdev; /* represents the device private info */ static u_char cn_phys_is_open; /* nonzero if physical device is open */ -static d_close_t *cn_phys_close; /* physical device close function */ -static d_open_t *cn_phys_open; /* physical device open function */ struct consdev *cn_tab; /* physical console device info */ static u_char console_pausing; /* pause after each line during probe */ static char *console_pausestr= ""; +static lwkt_port_t cn_fwd_port; +static struct lwkt_port cn_port; + + CONS_DRIVER(cons, NULL, NULL, NULL, NULL, NULL, NULL, NULL); void @@ -116,6 +122,12 @@ cninit() { struct consdev *best_cp, *cp, **list; + /* + * Our port intercept + */ + lwkt_init_port(&cn_port, NULL); + cn_port.mp_beginmsg = console_putport; + /* * Find the first console with the highest priority. */ @@ -170,21 +182,14 @@ cninit() void cninit_finish() { - struct cdevsw *cdp; - if ((cn_tab == NULL) || cn_mute) return; /* * Hook the open and close functions. */ - cdp = devsw(cn_tab->cn_dev); - if (cdp != NULL) { - cn_phys_close = cdp->d_close; - cdp->d_close = cnclose; - cn_phys_open = cdp->d_open; - cdp->d_open = cnopen; - } + if (dev_dport(cn_tab->cn_dev)) + cn_fwd_port = cdevsw_dev_override(cn_tab->cn_dev, &cn_port); cn_dev_t = cn_tab->cn_dev; cn_udev_t = dev2udev(cn_dev_t); console_pausing = 0; @@ -193,21 +198,14 @@ cninit_finish() static void cnuninit(void) { - struct cdevsw *cdp; - if (cn_tab == NULL) return; /* * Unhook the open and close functions. */ - cdp = devsw(cn_tab->cn_dev); - if (cdp != NULL) { - cdp->d_close = cn_phys_close; - cdp->d_open = cn_phys_open; - } - cn_phys_close = NULL; - cn_phys_open = NULL; + cdevsw_dev_override(cn_tab->cn_dev, NULL); + cn_fwd_port = NULL; cn_dev_t = NODEV; cn_udev_t = NOUDEV; } @@ -260,6 +258,36 @@ sysctl_kern_consmute(SYSCTL_HANDLER_ARGS) SYSCTL_PROC(_kern, OID_AUTO, consmute, CTLTYPE_INT|CTLFLAG_RW, 0, sizeof cn_mute, sysctl_kern_consmute, "I", ""); +static int +console_putport(lwkt_port_t port, lwkt_msg_t lmsg) +{ + cdevallmsg_t msg = (cdevallmsg_t)lmsg; + int error; + + switch(msg->am_lmsg.ms_cmd) { + case CDEV_CMD_OPEN: + error = cnopen( + msg->am_open.msg.dev, + msg->am_open.oflags, + msg->am_open.devtype, + msg->am_open.td + ); + break; + case CDEV_CMD_CLOSE: + error = cnclose( + msg->am_close.msg.dev, + msg->am_close.fflag, + msg->am_close.devtype, + msg->am_close.td + ); + break; + default: + error = lwkt_forwardmsg(cn_fwd_port, &msg->am_lmsg); + break; + } + return(error); +} + static int cnopen(dev, flag, mode, td) dev_t dev; @@ -269,7 +297,7 @@ cnopen(dev, flag, mode, td) dev_t cndev, physdev; int retval = 0; - if (cn_tab == NULL || cn_phys_open == NULL) + if (cn_tab == NULL || cn_fwd_port == NULL) return (0); cndev = cn_tab->cn_dev; physdev = (major(dev) == major(cndev) ? dev : cndev); @@ -279,7 +307,7 @@ cnopen(dev, flag, mode, td) * bypass this and go straight to the device. */ if(!cn_mute) - retval = (*cn_phys_open)(physdev, flag, mode, td); + retval = dev_port_dopen(cn_fwd_port, physdev, flag, mode, td); if (retval == 0) { /* * check if we openned it via /dev/console or @@ -306,7 +334,7 @@ cnclose(dev, flag, mode, td) dev_t cndev; struct tty *cn_tp; - if (cn_tab == NULL || cn_phys_open == NULL) + if (cn_tab == NULL || cn_fwd_port == NULL) return (0); cndev = cn_tab->cn_dev; cn_tp = cndev->si_tty; @@ -335,8 +363,8 @@ cnclose(dev, flag, mode, td) return (0); dev = cndev; } - if(cn_phys_close) - return ((*cn_phys_close)(dev, flag, mode, td)); + if (cn_fwd_port) + return (dev_port_dclose(cn_fwd_port, dev, flag, mode, td)); return (0); } @@ -347,10 +375,10 @@ cnread(dev, uio, flag) int flag; { - if (cn_tab == NULL || cn_phys_open == NULL) + if (cn_tab == NULL || cn_fwd_port == NULL) return (0); dev = cn_tab->cn_dev; - return ((*devsw(dev)->d_read)(dev, uio, flag)); + return (dev_port_dread(cn_fwd_port, dev, uio, flag)); } static int @@ -360,7 +388,7 @@ cnwrite(dev, uio, flag) int flag; { - if (cn_tab == NULL || cn_phys_open == NULL) { + if (cn_tab == NULL || cn_fwd_port == NULL) { uio->uio_resid = 0; /* dump the data */ return (0); } @@ -369,7 +397,7 @@ cnwrite(dev, uio, flag) else dev = cn_tab->cn_dev; log_console(uio); - return ((*devsw(dev)->d_write)(dev, uio, flag)); + return (dev_port_dwrite(cn_fwd_port, dev, uio, flag)); } static int @@ -382,7 +410,7 @@ cnioctl(dev, cmd, data, flag, td) { int error; - if (cn_tab == NULL || cn_phys_open == NULL) + if (cn_tab == NULL || cn_fwd_port == NULL) return (0); KKASSERT(td->td_proc != NULL); /* @@ -397,7 +425,7 @@ cnioctl(dev, cmd, data, flag, td) return (0); } dev = cn_tab->cn_dev; - return ((*devsw(dev)->d_ioctl)(dev, cmd, data, flag, td)); + return (dev_port_dioctl(cn_fwd_port, dev, cmd, data, flag, td)); } static int @@ -406,12 +434,12 @@ cnpoll(dev, events, td) int events; struct thread *td; { - if ((cn_tab == NULL) || cn_mute) + if ((cn_tab == NULL) || cn_mute || cn_fwd_port == NULL) return (1); dev = cn_tab->cn_dev; - return ((*devsw(dev)->d_poll)(dev, events, td)); + return (dev_port_dpoll(cn_fwd_port, dev, events, td)); } static int @@ -419,13 +447,11 @@ cnkqfilter(dev, kn) dev_t dev; struct knote *kn; { - if ((cn_tab == NULL) || cn_mute) + if ((cn_tab == NULL) || cn_mute || cn_fwd_port == NULL) return (1); dev = cn_tab->cn_dev; - if (devsw(dev)->d_flags & D_KQFILTER) - return ((*devsw(dev)->d_kqfilter)(dev, kn)); - return (1); + return (dev_port_dkqfilter(cn_fwd_port, dev, kn)); } int diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index 2d89f96f32..7e4c29c0eb 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -32,7 +32,7 @@ * * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95 * $FreeBSD: src/sys/kern/tty_pty.c,v 1.74.2.4 2002/02/20 19:58:13 dillon Exp $ - * $DragonFly: src/sys/kern/tty_pty.c,v 1.6 2003/07/21 05:50:43 dillon Exp $ + * $DragonFly: src/sys/kern/tty_pty.c,v 1.7 2003/07/22 17:03:33 dillon Exp $ */ /* @@ -55,6 +55,7 @@ #include #include #include +#include MALLOC_DEFINE(M_PTY, "ptys", "pty data structures"); @@ -99,7 +100,7 @@ static struct cdevsw pts_cdevsw = { static struct cdevsw ptc_cdevsw = { /* name */ "ptc", /* maj */ CDEV_MAJOR_C, - /* flags */ D_TTY | D_KQFILTER, + /* flags */ D_TTY | D_KQFILTER | D_MASTER, /* port */ NULL, /* autoq */ 0, @@ -666,7 +667,7 @@ ptyioctl(dev, cmd, data, flag, td) register u_char *cc = tp->t_cc; int stop, error; - if (devsw(dev)->d_open == ptcopen) { + if (dev_dflags(dev) & D_MASTER) { switch (cmd) { case TIOCGPGRP: diff --git a/sys/kern/vfs_conf.c b/sys/kern/vfs_conf.c index 63771c819a..1b771af777 100644 --- a/sys/kern/vfs_conf.c +++ b/sys/kern/vfs_conf.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/vfs_conf.c,v 1.49.2.5 2003/01/07 11:56:53 joerg Exp $ - * $DragonFly: src/sys/kern/vfs_conf.c,v 1.4 2003/07/06 21:23:51 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_conf.c,v 1.5 2003/07/22 17:03:33 dillon Exp $ */ /* @@ -57,6 +57,7 @@ #include #include #include +#include #include #include "opt_ddb.h" @@ -213,9 +214,10 @@ vfs_mountroot_try(char *mountfrom) printf("setrootbyname failed\n"); /* If the root device is a type "memory disk", mount RW */ - if (rootdev != NODEV && devsw(rootdev) && - (devsw(rootdev)->d_flags & D_MEMDISK)) + if (rootdev != NODEV && dev_dport(rootdev) && + (dev_dflags(rootdev) & D_MEMDISK)) { mp->mnt_flag &= ~MNT_RDONLY; + } error = VFS_MOUNT(mp, NULL, NULL, NULL, td); @@ -268,8 +270,8 @@ vfs_mountroot_ask(void) printf("Possibly valid devices for 'ufs' root:\n"); for (i = 0; i < NUMCDEVSW; i++) { dev = makedev(i, 0); - if (devsw(dev) != NULL) - printf(" \"%s\"", devsw(dev)->d_name); + if (dev_dport(dev) != NULL) + printf(" \"%s\"", dev_dname(dev)); } printf("\n"); continue; @@ -345,14 +347,14 @@ getdiskbyname(char *name) { *cp++ = '\0'; for (cd = 0; cd < NUMCDEVSW; cd++) { dev = makedev(cd, 0); - if (devsw(dev) != NULL && - strcmp(devsw(dev)->d_name, name) == 0) + if (dev_dport(dev) != NULL && + strcmp(dev_dname(dev), name) == 0) goto gotit; } printf("no such device '%s'\n", name); return (NODEV); gotit: - if (devsw(dev)->d_maj == major(rootdev)) + if (dev_dmaj(dev) == major(rootdev)) /* driver has already configured rootdev, e. g. vinum */ return (rootdev); if (unit == -1) { diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c index 79effea3c1..a48354ccc9 100644 --- a/sys/kern/vfs_default.c +++ b/sys/kern/vfs_default.c @@ -37,7 +37,7 @@ * * * $FreeBSD: src/sys/kern/vfs_default.c,v 1.28.2.7 2003/01/10 18:23:26 bde Exp $ - * $DragonFly: src/sys/kern/vfs_default.c,v 1.6 2003/07/19 21:14:39 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_default.c,v 1.7 2003/07/22 17:03:33 dillon Exp $ */ #include @@ -529,7 +529,7 @@ retry: if ((error = VOP_GETATTR(vp, &vat, td)) != 0) goto retn; object = vnode_pager_alloc(vp, vat.va_size, 0, 0); - } else if (devsw(vp->v_rdev) != NULL) { + } else if (dev_dport(vp->v_rdev) != NULL) { /* * This simply allocates the biggest object possible * for a disk vnode. This should be fixed, but doesn't diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index aade3b82cb..3c5eb7a605 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -37,7 +37,7 @@ * * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 * $FreeBSD: src/sys/kern/vfs_subr.c,v 1.249.2.30 2003/04/04 20:35:57 tegge Exp $ - * $DragonFly: src/sys/kern/vfs_subr.c,v 1.13 2003/07/22 05:04:41 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_subr.c,v 1.14 2003/07/22 17:03:33 dillon Exp $ */ /* @@ -3096,12 +3096,12 @@ vn_isdisk(vp, errp) *errp = ENXIO; return (0); } - if (!devsw(vp->v_rdev)) { + if (!dev_dport(vp->v_rdev)) { if (errp != NULL) *errp = ENXIO; return (0); } - if (!(devsw(vp->v_rdev)->d_flags & D_DISK)) { + if (!(dev_dflags(vp->v_rdev) & D_DISK)) { if (errp != NULL) *errp = ENOTBLK; return (0); diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 0c40b84ba1..1d21cb7ef1 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -37,7 +37,7 @@ * * @(#)vfs_vnops.c 8.2 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/vfs_vnops.c,v 1.87.2.13 2002/12/29 18:19:53 dillon Exp $ - * $DragonFly: src/sys/kern/vfs_vnops.c,v 1.8 2003/07/19 21:14:39 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_vnops.c,v 1.9 2003/07/22 17:03:33 dillon Exp $ */ #include @@ -587,7 +587,7 @@ vn_ioctl(struct file *fp, u_long com, caddr_t data, struct thread *td) if (com == FIODTYPE) { if (vp->v_type != VCHR && vp->v_type != VBLK) return (ENOTTY); - *(int *)data = devsw(vp->v_rdev)->d_flags & D_TYPEMASK; + *(int *)data = dev_dflags(vp->v_rdev) & D_TYPEMASK; return (0); } error = VOP_IOCTL(vp, com, data, fp->f_flag, ucred, td); diff --git a/sys/platform/pc32/i386/autoconf.c b/sys/platform/pc32/i386/autoconf.c index c539aba0db..7232eb55ba 100644 --- a/sys/platform/pc32/i386/autoconf.c +++ b/sys/platform/pc32/i386/autoconf.c @@ -35,7 +35,7 @@ * * from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91 * $FreeBSD: src/sys/i386/i386/autoconf.c,v 1.146.2.2 2001/06/07 06:05:58 dd Exp $ - * $DragonFly: src/sys/platform/pc32/i386/autoconf.c,v 1.6 2003/07/21 05:50:39 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/autoconf.c,v 1.7 2003/07/22 17:03:32 dillon Exp $ */ /* @@ -69,6 +69,7 @@ #include #include #include +#include #include #include @@ -304,7 +305,7 @@ setroot() } majdev = boot_translate_majdev(B_TYPE(bootdev)); dev = makedev(majdev, 0); - if (devsw(dev) == NULL) + if (dev_dport(dev) == NULL) return; unit = B_UNIT(bootdev); slice = B_SLICE(bootdev); diff --git a/sys/sys/buf.h b/sys/sys/buf.h index 22d6469add..f0b6a305f4 100644 --- a/sys/sys/buf.h +++ b/sys/sys/buf.h @@ -37,14 +37,21 @@ * * @(#)buf.h 8.9 (Berkeley) 3/30/95 * $FreeBSD: src/sys/sys/buf.h,v 1.88.2.10 2003/01/25 19:02:23 dillon Exp $ - * $DragonFly: src/sys/sys/buf.h,v 1.5 2003/07/06 21:23:54 dillon Exp $ + * $DragonFly: src/sys/sys/buf.h,v 1.6 2003/07/22 17:03:34 dillon Exp $ */ #ifndef _SYS_BUF_H_ #define _SYS_BUF_H_ +#ifndef _SYS_QUEUE_H_ #include +#endif +#ifndef _SYS_LOCK_H_ #include +#endif +#ifndef _SYS_DEVICE_H_ +#include +#endif struct buf; struct mount; diff --git a/sys/sys/conf.h b/sys/sys/conf.h index d8ac9a1a10..172e034765 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -37,7 +37,7 @@ * * @(#)conf.h 8.5 (Berkeley) 1/9/95 * $FreeBSD: src/sys/sys/conf.h,v 1.103.2.6 2002/03/11 01:14:55 dd Exp $ - * $DragonFly: src/sys/sys/conf.h,v 1.4 2003/07/21 05:50:47 dillon Exp $ + * $DragonFly: src/sys/sys/conf.h,v 1.5 2003/07/22 17:03:34 dillon Exp $ */ #ifndef _SYS_CONF_H_ @@ -123,30 +123,29 @@ struct thread; struct lwkt_port; typedef struct thread d_thread_t; -typedef int d_open_t __P((dev_t dev, int oflags, int devtype, d_thread_t *td)); -typedef int d_close_t __P((dev_t dev, int fflag, int devtype, d_thread_t *td)); -typedef void d_strategy_t __P((struct buf *bp)); -typedef int d_parms_t __P((dev_t dev, struct specinfo *sinfo, int ctl)); -typedef int d_ioctl_t __P((dev_t dev, u_long cmd, caddr_t data, - int fflag, d_thread_t *td)); -typedef int d_dump_t __P((dev_t dev)); -typedef int d_psize_t __P((dev_t dev)); - -typedef int d_read_t __P((dev_t dev, struct uio *uio, int ioflag)); -typedef int d_write_t __P((dev_t dev, struct uio *uio, int ioflag)); -typedef int d_poll_t __P((dev_t dev, int events, d_thread_t *td)); -typedef int d_kqfilter_t __P((dev_t dev, struct knote *kn)); -typedef int d_mmap_t __P((dev_t dev, vm_offset_t offset, int nprot)); - -typedef int l_open_t __P((dev_t dev, struct tty *tp)); -typedef int l_close_t __P((struct tty *tp, int flag)); -typedef int l_read_t __P((struct tty *tp, struct uio *uio, int flag)); -typedef int l_write_t __P((struct tty *tp, struct uio *uio, int flag)); -typedef int l_ioctl_t __P((struct tty *tp, u_long cmd, caddr_t data, - int flag, d_thread_t *td)); -typedef int l_rint_t __P((int c, struct tty *tp)); -typedef int l_start_t __P((struct tty *tp)); -typedef int l_modem_t __P((struct tty *tp, int flag)); +typedef int d_open_t (dev_t dev, int oflags, int devtype, d_thread_t *td); +typedef int d_close_t (dev_t dev, int fflag, int devtype, d_thread_t *td); +typedef void d_strategy_t (struct buf *bp); +typedef int d_ioctl_t (dev_t dev, u_long cmd, caddr_t data, + int fflag, d_thread_t *td); +typedef int d_dump_t (dev_t dev); +typedef int d_psize_t (dev_t dev); + +typedef int d_read_t (dev_t dev, struct uio *uio, int ioflag); +typedef int d_write_t (dev_t dev, struct uio *uio, int ioflag); +typedef int d_poll_t (dev_t dev, int events, d_thread_t *td); +typedef int d_kqfilter_t (dev_t dev, struct knote *kn); +typedef int d_mmap_t (dev_t dev, vm_offset_t offset, int nprot); + +typedef int l_open_t (dev_t dev, struct tty *tp); +typedef int l_close_t (struct tty *tp, int flag); +typedef int l_read_t (struct tty *tp, struct uio *uio, int flag); +typedef int l_write_t (struct tty *tp, struct uio *uio, int flag); +typedef int l_ioctl_t (struct tty *tp, u_long cmd, caddr_t data, + int flag, d_thread_t *td); +typedef int l_rint_t (int c, struct tty *tp); +typedef int l_start_t (struct tty *tp); +typedef int l_modem_t (struct tty *tp, int flag); /* * XXX: The dummy argument can be used to do what strategy1() never @@ -156,7 +155,7 @@ typedef int l_modem_t __P((struct tty *tp, int flag)); * of surgery, reset the flag and restart all the stuff on the stall * queue. */ -#define BUF_STRATEGY(bp, dummy) (*devsw((bp)->b_dev)->d_strategy)(bp) +#define BUF_STRATEGY(bp, dummy) dev_dstrategy((bp)->b_dev, bp) /* * Types for d_flags. */ @@ -174,6 +173,7 @@ typedef int l_modem_t __P((struct tty *tp, int flag)); #define D_NAGGED 0x00020000 /* nagged about missing make_dev() */ #define D_CANFREE 0x00040000 /* can free blocks */ #define D_TRACKCLOSE 0x00080000 /* track all closes */ +#define D_MASTER 0x00100000 /* used by pty/tty code */ #define D_KQFILTER 0x00200000 /* has kqfilter entry */ /* @@ -183,24 +183,24 @@ struct cdevsw { const char *d_name; /* base device name, e.g. 'vn' */ int d_maj; /* major (char) device number */ u_int d_flags; /* D_ flags */ - struct lwkt_port *d_port; + struct lwkt_port *d_port; /* port (template only) */ u_int d_autoq; /* thread safe (old style) vec mask */ /* * Old style vectors are used only if d_port is NULL when the cdevsw - * is added to the system. + * is added to the system. They have been renamed to prevent misuse. */ - d_open_t *d_open; - d_close_t *d_close; - d_read_t *d_read; - d_write_t *d_write; - d_ioctl_t *d_ioctl; - d_poll_t *d_poll; - d_mmap_t *d_mmap; - d_strategy_t *d_strategy; - d_dump_t *d_dump; - d_psize_t *d_psize; - d_kqfilter_t *d_kqfilter; + d_open_t *old_open; + d_close_t *old_close; + d_read_t *old_read; + d_write_t *old_write; + d_ioctl_t *old_ioctl; + d_poll_t *old_poll; + d_mmap_t *old_mmap; + d_strategy_t *old_strategy; + d_dump_t *old_dump; + d_psize_t *old_psize; + d_kqfilter_t *old_kqfilter; }; /* @@ -222,8 +222,8 @@ struct linesw { extern struct linesw linesw[]; extern int nlinesw; -int ldisc_register __P((int , struct linesw *)); -void ldisc_deregister __P((int)); +int ldisc_register (int , struct linesw *); +void ldisc_deregister (int); #define LDISC_LOAD -1 /* Loadable line discipline */ #endif @@ -284,18 +284,21 @@ static moduledata_t name##_mod = { \ }; \ DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE) - -int cdevsw_add __P((struct cdevsw *new)); -int cdevsw_remove __P((struct cdevsw *old)); -int count_dev __P((dev_t dev)); -void destroy_dev __P((dev_t dev)); -struct cdevsw *devsw __P((dev_t dev)); -const char *devtoname __P((dev_t dev)); -void freedev __P((dev_t dev)); -int iszerodev __P((dev_t dev)); -dev_t make_dev __P((struct cdevsw *devsw, int minor, uid_t uid, gid_t gid, int perms, const char *fmt, ...)) __printflike(6, 7); -int lminor __P((dev_t dev)); -void setconf __P((void)); +void compile_devsw(struct cdevsw *devsw); +int cdevsw_add (struct cdevsw *new); +struct lwkt_port *cdevsw_add_override (struct cdevsw *new, struct lwkt_port *port); +struct lwkt_port *cdevsw_dev_override(dev_t dev, struct lwkt_port *port); + +int cdevsw_remove (struct cdevsw *old); +int count_dev (dev_t dev); +void destroy_dev (dev_t dev); +struct cdevsw *devsw (dev_t dev); +const char *devtoname (dev_t dev); +void freedev (dev_t dev); +int iszerodev (dev_t dev); +dev_t make_dev (struct cdevsw *devsw, int minor, uid_t uid, gid_t gid, int perms, const char *fmt, ...) __printflike(6, 7); +int lminor (dev_t dev); +void setconf (void); dev_t getdiskbyname(char *name); /* diff --git a/sys/sys/device.h b/sys/sys/device.h new file mode 100644 index 0000000000..018aeb44dc --- /dev/null +++ b/sys/sys/device.h @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2003 Matthew Dillon + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $DragonFly: src/sys/sys/device.h,v 1.1 2003/07/22 17:03:34 dillon Exp $ + */ + +#ifndef _SYS_DEVICE_H_ +#define _SYS_DEVICE_H_ + +#ifndef _SYS_MSGPORT_H_ +#include +#endif + +/* + * This structure is at the base of every CDEVSW port message + */ +struct cdevmsg { + lwkt_msg msg; + dev_t dev; + struct cdevsw *csw; +}; + +/* + * int d_open(dev_t dev, int oflags, int devtype, thread_t td) + */ +struct cdevmsg_open { + struct cdevmsg msg; + int oflags; + int devtype; + struct thread *td; +}; + +/* + * int d_close(dev_t dev, int fflag, int devtype, thread_t td) + */ +struct cdevmsg_close { + struct cdevmsg msg; + int fflag; + int devtype; + struct thread *td; +}; + +/* + * void d_strategy(struct buf *bp) + */ +struct cdevmsg_strategy { + struct cdevmsg msg; + struct buf *bp; +}; + +/* + * int d_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, thread_t td) + */ +struct cdevmsg_ioctl { + struct cdevmsg msg; + u_long cmd; + caddr_t data; + int fflag; + struct thread *td; +}; + +/* + * void d_dump(dev_t dev) + */ +struct cdevmsg_dump { + struct cdevmsg msg; +}; + +/* + * int d_psize(dev_t dev) + */ +struct cdevmsg_psize { + struct cdevmsg msg; + int result; +}; + +/* + * int d_read(dev_t dev, struct uio *uio, int ioflag) + */ +struct cdevmsg_read { + struct cdevmsg msg; + struct uio *uio; + int ioflag; +}; + +/* + * int d_write(dev_t dev, struct uio *uio, int ioflag) + */ +struct cdevmsg_write { + struct cdevmsg msg; + struct uio *uio; + int ioflag; +}; + +/* + * int d_poll(dev_t dev, int events, thread_t td) + */ +struct cdevmsg_poll { + struct cdevmsg msg; + int events; + struct thread *td; +}; + +/* + * int d_kqfilter(dev_t dev, struct knote *kn) + */ +struct cdevmsg_kqfilter { + struct cdevmsg msg; + struct knote *kn; + int result; +}; + +/* + * int d_mmap(dev_t dev, vm_offset_t offset, int nprot) + */ +struct cdevmsg_mmap { + struct cdevmsg msg; + vm_offset_t offset; + int nprot; + int result; /* page number */ +}; + +union cdevallmsg { + struct lwkt_msg am_lmsg; + struct cdevmsg am_msg; + struct cdevmsg_open am_open; + struct cdevmsg_close am_close; + struct cdevmsg_strategy am_strategy; + struct cdevmsg_ioctl am_ioctl; + struct cdevmsg_dump am_dump; + struct cdevmsg_psize am_psize; + struct cdevmsg_read am_read; + struct cdevmsg_write am_write; + struct cdevmsg_poll am_poll; + struct cdevmsg_kqfilter am_kqfilter; + struct cdevmsg_mmap am_mmap; +}; + +typedef union cdevallmsg *cdevallmsg_t; +typedef struct cdevmsg *cdevmsg_t; +typedef struct cdevmsg_open *cdevmsg_open_t; +typedef struct cdevmsg_close *cdevmsg_close_t; +typedef struct cdevmsg_strategy *cdevmsg_strategy_t; +typedef struct cdevmsg_ioctl *cdevmsg_ioctl_t; +typedef struct cdevmsg_dump *cdevmsg_dump_t; +typedef struct cdevmsg_psize *cdevmsg_psize_t; +typedef struct cdevmsg_read *cdevmsg_read_t; +typedef struct cdevmsg_write *cdevmsg_write_t; +typedef struct cdevmsg_poll *cdevmsg_poll_t; +typedef struct cdevmsg_kqfilter *cdevmsg_kqfilter_t; +typedef struct cdevmsg_mmap *cdevmsg_mmap_t; + +#define CDEV_CMD_OPEN (MSG_CMD_CDEV|0x0001) +#define CDEV_CMD_CLOSE (MSG_CMD_CDEV|0x0002) +#define CDEV_CMD_STRATEGY (MSG_CMD_CDEV|0x0003) +#define CDEV_CMD_IOCTL (MSG_CMD_CDEV|0x0004) +#define CDEV_CMD_DUMP (MSG_CMD_CDEV|0x0005) +#define CDEV_CMD_PSIZE (MSG_CMD_CDEV|0x0006) +#define CDEV_CMD_READ (MSG_CMD_CDEV|0x0007) +#define CDEV_CMD_WRITE (MSG_CMD_CDEV|0x0008) +#define CDEV_CMD_POLL (MSG_CMD_CDEV|0x0009) +#define CDEV_CMD_KQFILTER (MSG_CMD_CDEV|0x000A) +#define CDEV_CMD_MMAP (MSG_CMD_CDEV|0x000B) + +#ifdef _KERNEL + +struct disk; + +const char *dev_dname(dev_t dev); +struct lwkt_port *dev_dport(dev_t dev); +int dev_dflags(dev_t dev); +int dev_dmaj(dev_t dev); +int dev_dopen(dev_t dev, int oflags, int devtype, struct thread *td); +int dev_dclose(dev_t dev, int fflag, int devtype, struct thread *td); +void dev_dstrategy(dev_t dev, struct buf *bp); +int dev_dioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td); +int dev_ddump(dev_t dev); +int dev_dpsize(dev_t dev); +int dev_dread(dev_t dev, struct uio *uio, int ioflag); +int dev_dwrite(dev_t dev, struct uio *uio, int ioflag); +int dev_dpoll(dev_t dev, int events, struct thread *td); +int dev_dkqfilter(dev_t dev, struct knote *kn); +int dev_dmmap(dev_t dev, vm_offset_t offset, int nprot); + +int dev_port_dopen(lwkt_port_t port, dev_t dev, int oflags, int devtype, struct thread *td); +int dev_port_dclose(lwkt_port_t port, dev_t dev, int fflag, int devtype, struct thread *td); +void dev_port_dstrategy(lwkt_port_t port, dev_t dev, struct buf *bp); +int dev_port_dioctl(lwkt_port_t port, dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td); +int dev_port_ddump(lwkt_port_t port, dev_t dev); +int dev_port_dpsize(lwkt_port_t port, dev_t dev); +int dev_port_dread(lwkt_port_t port, dev_t dev, struct uio *uio, int ioflag); +int dev_port_dwrite(lwkt_port_t port, dev_t dev, struct uio *uio, int ioflag); +int dev_port_dpoll(lwkt_port_t port, dev_t dev, int events, struct thread *td); +int dev_port_dkqfilter(lwkt_port_t port, dev_t dev, struct knote *kn); +int dev_port_dmmap(lwkt_port_t port, dev_t dev, vm_offset_t offset, int nprot); + +#endif + +#endif + diff --git a/sys/sys/disk.h b/sys/sys/disk.h index 1e4a0e3a2e..29e730c234 100644 --- a/sys/sys/disk.h +++ b/sys/sys/disk.h @@ -7,7 +7,7 @@ * ---------------------------------------------------------------------------- * * $FreeBSD: src/sys/sys/disk.h,v 1.16.2.3 2001/06/20 16:11:01 scottl Exp $ - * $DragonFly: src/sys/sys/disk.h,v 1.2 2003/06/17 04:28:58 dillon Exp $ + * $DragonFly: src/sys/sys/disk.h,v 1.3 2003/07/22 17:03:34 dillon Exp $ * */ @@ -16,16 +16,21 @@ #ifndef _SYS_DISKSLICE_H_ #include -#endif /* _SYS_DISKSLICE_H_ */ +#endif #ifndef _SYS_DISKLABEL #include -#endif /* _SYS_DISKLABEL */ +#endif + +#ifndef _SYS_DISKLABEL +#include +#endif struct disk { + struct lwkt_port d_port; /* interception port */ + struct lwkt_port *d_fwdport; /* forward to real port */ u_int d_flags; u_int d_dsflags; - struct cdevsw *d_devsw; dev_t d_dev; struct diskslices *d_slice; struct disklabel d_label; @@ -35,8 +40,8 @@ struct disk { #define DISKFLAG_LOCK 0x1 #define DISKFLAG_WANTED 0x2 -dev_t disk_create __P((int unit, struct disk *disk, int flags, struct cdevsw *cdevsw, struct cdevsw *diskdevsw)); -void disk_destroy __P((dev_t dev)); +dev_t disk_create __P((int unit, struct disk *disk, int flags, struct cdevsw *cdevsw)); +void disk_destroy __P((struct disk *disk)); int disk_dumpcheck __P((dev_t dev, u_int *count, u_int *blkno, u_int *secsize)); struct disk *disk_enumerate __P((struct disk *disk)); void disk_invalidate __P((struct disk *disk)); diff --git a/sys/sys/msgport.h b/sys/sys/msgport.h index ddd3105f77..a38c6e8bca 100644 --- a/sys/sys/msgport.h +++ b/sys/sys/msgport.h @@ -3,7 +3,7 @@ * * Implements LWKT messages and ports. * - * $DragonFly: src/sys/sys/msgport.h,v 1.1 2003/07/20 01:37:22 dillon Exp $ + * $DragonFly: src/sys/sys/msgport.h,v 1.2 2003/07/22 17:03:34 dillon Exp $ */ #ifndef _SYS_MSGPORT_H_ @@ -15,10 +15,13 @@ struct lwkt_msg; struct lwkt_port; +struct thread; typedef struct lwkt_msg *lwkt_msg_t; typedef struct lwkt_port *lwkt_port_t; +typedef TAILQ_HEAD(lwkt_msg_queue, lwkt_msg) lwkt_msg_queue; + /* * The standard message and port structure for communications between * threads. See kern/lwkt_msgport.c for documentation on how messages and @@ -39,10 +42,15 @@ typedef struct lwkt_msg { #define MSGF_QUEUED 0x0004 /* message has been queued sanitychk */ #define MSGF_ASYNC 0x0008 /* sync/async hint */ +#define MSG_CMD_CDEV 0x00010000 +#define MSG_CMD_VFS 0x00020000 +#define MSG_CMD_SYSCALL 0x00030000 +#define MSG_SUBCMD_MASK 0x0000FFFF + typedef struct lwkt_port { lwkt_msg_queue mp_msgq; int mp_flags; - thread_t mp_td; + struct thread *mp_td; int (*mp_beginmsg)(lwkt_port_t port, lwkt_msg_t msg); void (*mp_abortmsg)(lwkt_port_t port, lwkt_msg_t msg); void (*mp_returnmsg)(lwkt_port_t port, lwkt_msg_t msg); @@ -52,7 +60,7 @@ typedef struct lwkt_port { #ifdef _KERNEL -extern void lwkt_init_port(lwkt_port_t port, thread_t td); +extern void lwkt_init_port(lwkt_port_t port, struct thread *td); extern void lwkt_sendmsg(lwkt_port_t port, lwkt_msg_t msg); extern int lwkt_domsg(lwkt_port_t port, lwkt_msg_t msg); extern int lwkt_waitmsg(lwkt_msg_t msg); diff --git a/sys/sys/msgport2.h b/sys/sys/msgport2.h index cb7b2e032f..3390d8a2bb 100644 --- a/sys/sys/msgport2.h +++ b/sys/sys/msgport2.h @@ -3,12 +3,20 @@ * * Implements Inlines for LWKT messages and ports. * - * $DragonFly: src/sys/sys/msgport2.h,v 1.1 2003/07/20 01:37:22 dillon Exp $ + * $DragonFly: src/sys/sys/msgport2.h,v 1.2 2003/07/22 17:03:34 dillon Exp $ */ #ifndef _SYS_MSGPORT2_H_ #define _SYS_MSGPORT2_H_ +static __inline +void +lwkt_initmsg(lwkt_msg_t msg, int cmd) +{ + msg->ms_cmd = cmd; + msg->ms_flags = MSGF_DONE; +} + #ifdef _KERNEL static __inline diff --git a/sys/sys/thread.h b/sys/sys/thread.h index 225d102d10..3321e6cf9f 100644 --- a/sys/sys/thread.h +++ b/sys/sys/thread.h @@ -4,7 +4,7 @@ * Implements the architecture independant portion of the LWKT * subsystem. * - * $DragonFly: src/sys/sys/thread.h,v 1.25 2003/07/20 01:37:22 dillon Exp $ + * $DragonFly: src/sys/sys/thread.h,v 1.26 2003/07/22 17:03:34 dillon Exp $ */ #ifndef _SYS_THREAD_H_ @@ -37,7 +37,6 @@ typedef struct lwkt_ipiq *lwkt_ipiq_t; typedef struct thread *thread_t; typedef TAILQ_HEAD(lwkt_queue, thread) lwkt_queue; -typedef TAILQ_HEAD(lwkt_msg_queue, lwkt_msg) lwkt_msg_queue; #ifndef _MACHINE_THREAD_H_ #include /* md_thread */ diff --git a/sys/vfs/coda/coda_vfsops.c b/sys/vfs/coda/coda_vfsops.c index dd673f9ec3..1faf4a57f6 100644 --- a/sys/vfs/coda/coda_vfsops.c +++ b/sys/vfs/coda/coda_vfsops.c @@ -28,7 +28,7 @@ * * @(#) src/sys/cfs/coda_vfsops.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ * $FreeBSD: src/sys/coda/coda_vfsops.c,v 1.24.2.1 2001/07/26 20:36:45 iedowse Exp $ - * $DragonFly: src/sys/vfs/coda/Attic/coda_vfsops.c,v 1.5 2003/06/26 05:55:07 dillon Exp $ + * $DragonFly: src/sys/vfs/coda/Attic/coda_vfsops.c,v 1.6 2003/07/22 17:03:23 dillon Exp $ * */ @@ -155,6 +155,7 @@ coda_mount(vfsp, path, data, ndp, td) vrele(dvp); NDFREE(ndp, NDF_ONLY_PNBUF); +#if 0 /* YYY huh? what paranoia is this? */ /* * See if the device table matches our expectations. */ @@ -163,6 +164,7 @@ coda_mount(vfsp, path, data, ndp, td) MARK_INT_FAIL(CODA_MOUNT_STATS); return(ENXIO); } +#endif if (minor(dev) >= NVCODA || minor(dev) < 0) { MARK_INT_FAIL(CODA_MOUNT_STATS); diff --git a/sys/vfs/isofs/cd9660/cd9660_vfsops.c b/sys/vfs/isofs/cd9660/cd9660_vfsops.c index 6ef303f155..a67f05d5ad 100644 --- a/sys/vfs/isofs/cd9660/cd9660_vfsops.c +++ b/sys/vfs/isofs/cd9660/cd9660_vfsops.c @@ -37,7 +37,7 @@ * * @(#)cd9660_vfsops.c 8.18 (Berkeley) 5/22/95 * $FreeBSD: src/sys/isofs/cd9660/cd9660_vfsops.c,v 1.74.2.7 2002/04/08 09:39:29 bde Exp $ - * $DragonFly: src/sys/vfs/isofs/cd9660/cd9660_vfsops.c,v 1.6 2003/07/19 21:14:38 dillon Exp $ + * $DragonFly: src/sys/vfs/isofs/cd9660/cd9660_vfsops.c,v 1.7 2003/07/22 17:03:32 dillon Exp $ */ #include @@ -115,22 +115,16 @@ iso_get_ssector(dev_t dev, struct thread *td) struct ioc_toc_header h; struct ioc_read_toc_single_entry t; int i; - struct cdevsw *bd; - d_ioctl_t *ioctlp; - bd = devsw(dev); - ioctlp = bd->d_ioctl; - if (ioctlp == NULL) - return 0; - - if (ioctlp(dev, CDIOREADTOCHEADER, (caddr_t)&h, FREAD, td) != 0) + if (dev_dioctl(dev, CDIOREADTOCHEADER, (caddr_t)&h, FREAD, td) != 0) return 0; for (i = h.ending_track; i >= 0; i--) { t.address_format = CD_LBA_FORMAT; t.track = i; - if (ioctlp(dev, CDIOREADTOCENTRY, (caddr_t)&t, FREAD, td) != 0) + if (dev_dioctl(dev, CDIOREADTOCENTRY, (caddr_t)&t, FREAD, td) != 0) { return 0; + } if ((t.entry.control & 4) != 0) /* found a data track */ break; diff --git a/sys/vfs/specfs/spec_vnops.c b/sys/vfs/specfs/spec_vnops.c index d09a61f92b..5d1a681ff9 100644 --- a/sys/vfs/specfs/spec_vnops.c +++ b/sys/vfs/specfs/spec_vnops.c @@ -32,7 +32,7 @@ * * @(#)spec_vnops.c 8.14 (Berkeley) 5/21/95 * $FreeBSD: src/sys/miscfs/specfs/spec_vnops.c,v 1.131.2.4 2001/02/26 04:23:20 jlemon Exp $ - * $DragonFly: src/sys/vfs/specfs/spec_vnops.c,v 1.10 2003/07/19 21:14:42 dillon Exp $ + * $DragonFly: src/sys/vfs/specfs/spec_vnops.c,v 1.11 2003/07/22 17:03:33 dillon Exp $ */ #include @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -140,7 +141,6 @@ spec_open(ap) struct vnode *vp = ap->a_vp; dev_t dev = vp->v_rdev; int error; - struct cdevsw *dsw; const char *cp; /* @@ -149,8 +149,7 @@ spec_open(ap) if (vp->v_mount && (vp->v_mount->mnt_flag & MNT_NODEV)) return (ENXIO); - dsw = devsw(dev); - if ( (dsw == NULL) || (dsw->d_open == NULL)) + if (dev_dport(dev) == NULL) return ENXIO; /* Make this field valid before any I/O in ->d_open */ @@ -188,17 +187,17 @@ spec_open(ap) } /* XXX: Special casing of ttys for deadfs. Probably redundant */ - if (dsw->d_flags & D_TTY) + if (dev_dflags(dev) & D_TTY) vp->v_flag |= VISTTY; VOP_UNLOCK(vp, 0, ap->a_td); - error = (*dsw->d_open)(dev, ap->a_mode, S_IFCHR, ap->a_td); + error = dev_dopen(dev, ap->a_mode, S_IFCHR, ap->a_td); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, ap->a_td); if (error) return (error); - if (dsw->d_flags & D_TTY) { + if (dev_dflags(dev) & D_TTY) { if (dev->si_tty) { struct tty *tp; tp = dev->si_tty; @@ -213,12 +212,11 @@ spec_open(ap) if (!dev->si_bsize_phys) dev->si_bsize_phys = DEV_BSIZE; } - if ((dsw->d_flags & D_DISK) == 0) { + if ((dev_dflags(dev) & D_DISK) == 0) { cp = devtoname(dev); - if (*cp == '#' && (dsw->d_flags & D_NAGGED) == 0) { + if (*cp == '#') { printf("WARNING: driver %s should register devices with make_dev() (dev_t = \"%s\")\n", - dsw->d_name, cp); - dsw->d_flags |= D_NAGGED; + dev_dname(dev), cp); } } return (error); @@ -252,7 +250,7 @@ spec_read(ap) return (0); VOP_UNLOCK(vp, 0, td); - error = (*devsw(dev)->d_read) (dev, uio, ap->a_ioflag); + error = dev_dread(dev, uio, ap->a_ioflag); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); return (error); } @@ -282,7 +280,7 @@ spec_write(ap) td = uio->uio_td; VOP_UNLOCK(vp, 0, td); - error = (*devsw(dev)->d_write) (dev, uio, ap->a_ioflag); + error = dev_dwrite(dev, uio, ap->a_ioflag); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); return (error); } @@ -305,8 +303,8 @@ spec_ioctl(ap) dev_t dev; dev = ap->a_vp->v_rdev; - return ((*devsw(dev)->d_ioctl)(dev, ap->a_command, - ap->a_data, ap->a_fflag, ap->a_td)); + return (dev_dioctl(dev, ap->a_command, ap->a_data, + ap->a_fflag, ap->a_td)); } /* ARGSUSED */ @@ -322,7 +320,7 @@ spec_poll(ap) dev_t dev; dev = ap->a_vp->v_rdev; - return (*devsw(dev)->d_poll)(dev, ap->a_events, ap->a_td); + return (dev_dpoll(dev, ap->a_events, ap->a_td)); } /* ARGSUSED */ @@ -336,9 +334,7 @@ spec_kqfilter(ap) dev_t dev; dev = ap->a_vp->v_rdev; - if (devsw(dev)->d_flags & D_KQFILTER) - return (*devsw(dev)->d_kqfilter)(dev, ap->a_kn); - return (1); + return (dev_dkqfilter(dev, ap->a_kn)); } /* @@ -472,12 +468,14 @@ spec_strategy(ap) mp->mnt_stat.f_syncreads++; } } +#if 0 KASSERT(devsw(bp->b_dev) != NULL, ("No devsw on dev %s responsible for buffer %p\n", devtoname(bp->b_dev), bp)); KASSERT(devsw(bp->b_dev)->d_strategy != NULL, ("No strategy on dev %s responsible for buffer %p\n", devtoname(bp->b_dev), bp)); +#endif BUF_STRATEGY(bp, 0); return (0); } @@ -490,15 +488,13 @@ spec_freeblks(ap) daddr_t a_length; } */ *ap; { - struct cdevsw *bsw; struct buf *bp; /* * XXX: This assumes that strategy does the deed right away. * XXX: this may not be TRTTD. */ - bsw = devsw(ap->a_vp->v_rdev); - if ((bsw->d_flags & D_CANFREE) == 0) + if ((dev_dflags(ap->a_vp->v_rdev) & D_CANFREE) == 0) return (0); bp = geteblk(ap->a_length); bp->b_flags |= B_FREEBUF; @@ -585,12 +581,12 @@ spec_close(ap) */ if (vp->v_flag & VXLOCK) { /* Forced close */ - } else if (devsw(dev)->d_flags & D_TRACKCLOSE) { + } else if (dev_dflags(dev) & D_TRACKCLOSE) { /* Keep device updated on status */ } else if (vcount(vp) > 1) { return (0); } - return (devsw(dev)->d_close(dev, ap->a_fflag, S_IFCHR, ap->a_td)); + return (dev_dclose(dev, ap->a_fflag, S_IFCHR, ap->a_td)); } /* diff --git a/sys/vfs/ufs/ufs_disksubr.c b/sys/vfs/ufs/ufs_disksubr.c index 268b77c1e9..ef07d1cee3 100644 --- a/sys/vfs/ufs/ufs_disksubr.c +++ b/sys/vfs/ufs/ufs_disksubr.c @@ -37,7 +37,7 @@ * * @(#)ufs_disksubr.c 8.5 (Berkeley) 1/21/94 * $FreeBSD: src/sys/ufs/ufs/ufs_disksubr.c,v 1.44.2.3 2001/03/05 05:42:19 obrien Exp $ - * $DragonFly: src/sys/vfs/ufs/Attic/ufs_disksubr.c,v 1.3 2003/06/19 01:55:08 dillon Exp $ + * $DragonFly: src/sys/vfs/ufs/Attic/ufs_disksubr.c,v 1.4 2003/07/22 17:03:35 dillon Exp $ */ #include @@ -48,6 +48,7 @@ #include #include #include +#include #include diff --git a/sys/vm/device_pager.c b/sys/vm/device_pager.c index b78afbd1f4..9be654c59e 100644 --- a/sys/vm/device_pager.c +++ b/sys/vm/device_pager.c @@ -37,13 +37,14 @@ * * @(#)device_pager.c 8.1 (Berkeley) 6/11/93 * $FreeBSD: src/sys/vm/device_pager.c,v 1.46.2.1 2000/08/02 21:54:37 peter Exp $ - * $DragonFly: src/sys/vm/device_pager.c,v 1.3 2003/07/19 21:14:53 dillon Exp $ + * $DragonFly: src/sys/vm/device_pager.c,v 1.4 2003/07/22 17:03:35 dillon Exp $ */ #include #include #include #include +#include #include #include @@ -94,7 +95,6 @@ static vm_object_t dev_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot, vm_ooffset_t foff) { dev_t dev; - d_mmap_t *mapfunc; vm_object_t object; unsigned int npages; vm_offset_t off; @@ -103,11 +103,6 @@ dev_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot, vm_ooffset_t fo * Make sure this device can be mapped. */ dev = handle; - mapfunc = devsw(dev)->d_mmap; - if (mapfunc == NULL || mapfunc == (d_mmap_t *)nullop) { - printf("obsolete map function %p\n", (void *)mapfunc); - return (NULL); - } /* * Offset should be page aligned. @@ -124,9 +119,10 @@ dev_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot, vm_ooffset_t fo * XXX assumes VM_PROT_* == PROT_* */ npages = OFF_TO_IDX(size); - for (off = foff; npages--; off += PAGE_SIZE) - if ((*mapfunc) (dev, off, (int) prot) == -1) + for (off = foff; npages--; off += PAGE_SIZE) { + if (dev_dmmap(dev, off, (int)prot) == -1) return (NULL); + } /* * Lock to prevent object creation race condition. @@ -195,18 +191,13 @@ dev_pager_getpages(object, m, count, reqpage) vm_page_t page; dev_t dev; int i, s; - d_mmap_t *mapfunc; int prot; dev = object->handle; offset = m[reqpage]->pindex; prot = PROT_READ; /* XXX should pass in? */ - mapfunc = devsw(dev)->d_mmap; - - if (mapfunc == NULL || mapfunc == (d_mmap_t *)nullop) - panic("dev_pager_getpage: no map function"); - paddr = pmap_phys_address((*mapfunc) (dev, (vm_offset_t) offset << PAGE_SHIFT, prot)); + paddr = pmap_phys_address(dev_dmmap(dev, (vm_offset_t) offset << PAGE_SHIFT, prot)); KASSERT(paddr != -1,("dev_pager_getpage: map function returns error")); /* * Replace the passed in reqpage page with our own fake page and free up the diff --git a/sys/vm/vm_rangelock.c b/sys/vm/vm_rangelock.c new file mode 100644 index 0000000000..01ec42cfa5 --- /dev/null +++ b/sys/vm/vm_rangelock.c @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2003 Matthew Dillon + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * VM range locking module. Range locks within VM objects are used to protect + * I/O operations and will eventually also be used in an extended form + * for cache coherency control. + * + * $DragonFly: src/sys/vm/vm_rangelock.c,v 1.1 2003/07/22 17:03:35 dillon Exp $ + */ +#include +#include +#include /* for curproc, pageproc */ +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Note: these routines are currently greatly simplified and unoptimized. + * + * Locks are sorted by base address. + */ +void +shlock_range(vm_object_lock_t lock, vm_object_t object, off_t base, off_t bytes) +{ + struct vm_object_lock **plock; + vm_object_lock_t scan; + + /* + * Locate the insertion point and check for conflicts + */ +again: + for (plock = &object->range_locks; + (scan = *plock) != NULL; + plock = &scan->next + ) { + if (base < scan->base + scan->bytes && base + bytes > scan->base) { + if (scan->type != VMOBJ_LOCK_SHARED) { + tsleep(scan + } + } + } +} + +void +exlock_range(vm_object_lock_t lock, vm_object_t object, off_t base, off_t bytes) +{ +} + +void +unlock_range(vm_object_lock_t lock) +{ +} + diff --git a/sys/vm/vm_swap.c b/sys/vm/vm_swap.c index d27c48f107..211b24d8eb 100644 --- a/sys/vm/vm_swap.c +++ b/sys/vm/vm_swap.c @@ -32,7 +32,7 @@ * * @(#)vm_swap.c 8.5 (Berkeley) 2/17/94 * $FreeBSD: src/sys/vm/vm_swap.c,v 1.96.2.2 2001/10/14 18:46:47 iedowse Exp $ - * $DragonFly: src/sys/vm/vm_swap.c,v 1.5 2003/06/26 05:55:21 dillon Exp $ + * $DragonFly: src/sys/vm/vm_swap.c,v 1.6 2003/07/22 17:03:35 dillon Exp $ */ #include "opt_swap.h" @@ -270,8 +270,7 @@ swaponvp(struct thread *td, struct vnode *vp, dev_t dev, u_long nblks) if (error) return (error); - if (nblks == 0 && dev != NODEV && (devsw(dev)->d_psize == 0 || - (nblks = (*devsw(dev)->d_psize) (dev)) == -1)) { + if (nblks == 0 && dev != NODEV && ((nblks = dev_dpsize(dev)) == -1)) { (void) VOP_CLOSE(vp, FREAD | FWRITE, td); return (ENXIO); } -- 2.41.0