changeset 25255:d352d99f7497

12997 clean up stale vdev driver in bhyve Reviewed by: Andy Fiddaman <andy@omniosce.org> Approved by: Robert Mustacchi <rm@fingolfin.org>
author Patrick Mooney <pmooney@pfmooney.com>
date Tue, 28 Jul 2020 20:24:52 +0000
parents e14cdb6b4657
children c6fb4943e10c b821679919bb
files usr/src/uts/i86pc/Makefile.files usr/src/uts/i86pc/io/vmm/io/vdev.c usr/src/uts/i86pc/io/vmm/io/vdev.h
diffstat 3 files changed, 0 insertions(+), 379 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/uts/i86pc/Makefile.files	Sun Jul 26 22:59:54 2020 +0300
+++ b/usr/src/uts/i86pc/Makefile.files	Tue Jul 28 20:24:52 2020 +0000
@@ -248,7 +248,6 @@
 	vmm_util.o \
 	x86.o \
 	iommu.o \
-	vdev.o \
 	vatpic.o \
 	vatpit.o \
 	vhpet.o \
--- a/usr/src/uts/i86pc/io/vmm/io/vdev.c	Sun Jul 26 22:59:54 2020 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,282 +0,0 @@
-/*-
- * Copyright (c) 2011 NetApp, Inc.
- * 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 NETAPP, INC ``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 NETAPP, INC 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.
- *
- * $FreeBSD: head/sys/amd64/vmm/io/vdev.c 245678 2013-01-20 03:42:49Z neel $
- */
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- *
- * Copyright 2013 Pluribus Networks Inc.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/amd64/vmm/io/vdev.c 245678 2013-01-20 03:42:49Z neel $");
-
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-
-#include "vdev.h"
-
-struct vdev {
-	SLIST_ENTRY(vdev) 	 entry;
-	struct vdev_ops 	*ops;
-	void			*dev;
-};
-static SLIST_HEAD(, vdev)	vdev_head;
-static int 		  	vdev_count;
-
-struct vdev_region {
-	SLIST_ENTRY(vdev_region) 	 entry;
-	struct vdev_ops 		*ops;
-	void				*dev;
-	struct io_region		*io;
-};
-static SLIST_HEAD(, vdev_region)	 region_head;
-static int 		  		 region_count;
-
-static MALLOC_DEFINE(M_VDEV, "vdev", "vdev");
-
-#define VDEV_INIT 	(0)
-#define VDEV_RESET	(1)
-#define VDEV_HALT	(2)
-
-// static const char* vdev_event_str[] = {"VDEV_INIT", "VDEV_RESET", "VDEV_HALT"};
-
-static int
-vdev_system_event(int event)
-{
-	struct vdev 	*vd;
-	int		 rc;
-
-	// TODO: locking
-	SLIST_FOREACH(vd, &vdev_head, entry) {
-		// printf("%s : %s Device %s\n", __func__, vdev_event_str[event], vd->ops->name);
-		switch (event) {
-			case VDEV_INIT:
-				rc = vd->ops->init(vd->dev);
-				break;
-			case VDEV_RESET:
-				rc = vd->ops->reset(vd->dev);
-				break;
-			case VDEV_HALT:
-				rc = vd->ops->halt(vd->dev);
-				break;
-			default:
-				break;
-		}
-		if (rc) {
-			printf("vdev %s init failed rc=%d\n",
-			    vd->ops->name, rc);
-			return rc;
-		}
-	}
-	return 0;
-}
-
-int
-vdev_init(void)
-{
-	return vdev_system_event(VDEV_INIT);
-}
-
-int
-vdev_reset(void)
-{
-	return vdev_system_event(VDEV_RESET);
-}
-
-int
-vdev_halt(void)
-{
-	return vdev_system_event(VDEV_HALT);
-}
-
-void
-vdev_vm_init(void)
-{
-	SLIST_INIT(&vdev_head);
-	vdev_count = 0;
-
-	SLIST_INIT(&region_head);
-	region_count = 0;
-}
-void
-vdev_vm_cleanup(void)
-{
-	struct vdev *vd;
-     
-	// TODO: locking
-	while (!SLIST_EMPTY(&vdev_head)) {
-		vd = SLIST_FIRST(&vdev_head);
-		SLIST_REMOVE_HEAD(&vdev_head, entry);
-		free(vd, M_VDEV);
-		vdev_count--;
-	}
-}
-
-int
-vdev_register(struct vdev_ops *ops, void *dev)
-{
-	struct vdev *vd;
-	vd = malloc(sizeof(*vd), M_VDEV, M_WAITOK | M_ZERO); 
-	vd->ops = ops;
-	vd->dev = dev;
-	
-	// TODO: locking
-	SLIST_INSERT_HEAD(&vdev_head, vd, entry); 
-	vdev_count++;
-	return 0;
-}
-
-void
-vdev_unregister(void *dev)
-{
-	struct vdev 	*vd, *found;
-
-	found = NULL;
-	// TODO: locking
-	SLIST_FOREACH(vd, &vdev_head, entry) {
-		if (vd->dev == dev) {
-			found = vd;
-		}
-	}
-
-	if (found) {
-		SLIST_REMOVE(&vdev_head, found, vdev, entry);
-		free(found, M_VDEV);
-	}
-}
-
-#define IN_RANGE(val, start, end)	\
-    (((val) >= (start)) && ((val) < (end)))
-
-static struct vdev_region*
-vdev_find_region(struct io_region *io, void *dev) 
-{
-	struct 		vdev_region *region, *found;
-	uint64_t	region_base;
-	uint64_t	region_end;
-
-	found = NULL;
-
-	// TODO: locking
-	// FIXME: we should verify we are in the context the current
-	// 	  vcpu here as well.
-	SLIST_FOREACH(region, &region_head, entry) {
-		region_base = region->io->base;
-		region_end = region_base + region->io->len;
-		if (IN_RANGE(io->base, region_base, region_end) &&
-		    IN_RANGE(io->base+io->len, region_base, region_end+1) &&
-		    (dev && dev == region->dev)) {
-			found = region;
-			break;
-		}
-	}
-	return found;
-}
-
-int
-vdev_register_region(struct vdev_ops *ops, void *dev, struct io_region *io)
-{
-	struct vdev_region *region;
-
-	region = vdev_find_region(io, dev);
-	if (region) {
-		return -EEXIST;
-	}
-
-	region = malloc(sizeof(*region), M_VDEV, M_WAITOK | M_ZERO);
-	region->io = io;
-	region->ops = ops;
-	region->dev = dev;
-
-	// TODO: locking
-	SLIST_INSERT_HEAD(&region_head, region, entry); 
-	region_count++;
-
-	return 0;
-}
-
-void
-vdev_unregister_region(void *dev, struct io_region *io)
-{
-	struct vdev_region *region;
-
-	region = vdev_find_region(io, dev);
-	
-	if (region) {
-		SLIST_REMOVE(&region_head, region, vdev_region, entry);
-		free(region, M_VDEV);
-		region_count--;
-	}
-}
-
-static int
-vdev_memrw(uint64_t gpa, opsize_t size, uint64_t *data, int read)
-{
-	struct vdev_region 	*region;
-	struct io_region	 io;
-	region_attr_t		 attr;
-	int			 rc;
-
-	io.base = gpa;
-	io.len = size;
-
-	region = vdev_find_region(&io, NULL);
-	if (!region)
-		return -EINVAL;
-	
-	attr = (read) ? MMIO_READ : MMIO_WRITE;
-	if (!(region->io->attr & attr))
-		return -EPERM;
-
-	if (read)
-		rc = region->ops->memread(region->dev, gpa, size, data);
-	else 
-		rc = region->ops->memwrite(region->dev, gpa, size, *data);
-
-	return rc;
-}
-
-int
-vdev_memread(uint64_t gpa, opsize_t size, uint64_t *data)
-{
-	return vdev_memrw(gpa, size, data, 1);
-}
-
-int
-vdev_memwrite(uint64_t gpa, opsize_t size, uint64_t data)
-{
-	return vdev_memrw(gpa, size, &data, 0);
-}
--- a/usr/src/uts/i86pc/io/vmm/io/vdev.h	Sun Jul 26 22:59:54 2020 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,96 +0,0 @@
-/*-
- * Copyright (c) 2011 NetApp, Inc.
- * 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 NETAPP, INC ``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 NETAPP, INC 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.
- *
- * $FreeBSD: head/sys/amd64/vmm/io/vdev.h 245678 2013-01-20 03:42:49Z neel $
- */
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- *
- * Copyright 2013 Pluribus Networks Inc.
- */
-
-#ifndef _VDEV_H_
-#define	_VDEV_H_
-
-typedef enum {
-	BYTE	= 1,
-	WORD	= 2,
-	DWORD	= 4,
-	QWORD	= 8,
-} opsize_t;
-
-typedef enum {
-	MMIO_READ = 1,
-	MMIO_WRITE = 2,
-} region_attr_t;
-
-struct io_region {
-	uint64_t	base;
-	uint64_t	len;
-	region_attr_t	attr;
-	int		vcpu;
-};
-
-typedef int (*vdev_init_t)(void* dev);
-typedef int (*vdev_reset_t)(void* dev);
-typedef int (*vdev_halt_t)(void* dev);
-typedef int (*vdev_memread_t)(void* dev, uint64_t gpa, opsize_t size, uint64_t *data);
-typedef int (*vdev_memwrite_t)(void* dev, uint64_t gpa, opsize_t size, uint64_t data);
-
-
-struct vdev_ops {
-	const char	*name;
-	vdev_init_t	init;
-	vdev_reset_t	reset;
-	vdev_halt_t	halt;
-	vdev_memread_t	memread;
-	vdev_memwrite_t	memwrite;
-};
-
-
-void vdev_vm_init(void);
-void vdev_vm_cleanup(void);
-
-int  vdev_register(struct vdev_ops *ops, void *dev);
-void vdev_unregister(void *dev);
-
-int  vdev_register_region(struct vdev_ops *ops, void *dev, struct io_region *io);
-void vdev_unregister_region(void *dev, struct io_region *io);
-
-int vdev_init(void);
-int vdev_reset(void);
-int vdev_halt(void);
-int vdev_memread(uint64_t gpa, opsize_t size, uint64_t *data);
-int vdev_memwrite(uint64_t gpa, opsize_t size, uint64_t data);
-
-#endif	/* _VDEV_H_ */
-