Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Oct 2013 22:01:17 +0000 (UTC)
From:      Peter Grehan <grehan@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r256711 - head/usr.sbin/bhyve
Message-ID:  <201310172201.r9HM1HCf073642@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: grehan
Date: Thu Oct 17 22:01:17 2013
New Revision: 256711
URL: http://svnweb.freebsd.org/changeset/base/256711

Log:
  Changes required for OpenBSD/amd64:
  
  - Allow a hostbridge to be created with AMD as a vendor.
    This passes the OpenBSD check to allow the use of MSI
    on a PCI bus.
  - Enable the i/o interrupt section of the mptable, and
    populate it with unity ISA mappings. This allows the
    'legacy' IRQ mappings of the PCI serial port to be
    set up. Delete unused print routine that was obscuring code.
  - Use the '-W' option to enable virtio single-vector MSI
    rather than an environment variable. Update the virtio
    net/block drivers to query this flag when setting up
    interrupts.: bhyverun.c
  - Fix the arithmetic used to derive the century byte in
    RTC CMOS, as well as encoding it in BCD.
  
  Reviewed by:	neel
  MFC after:	3 days

Modified:
  head/usr.sbin/bhyve/bhyverun.c
  head/usr.sbin/bhyve/bhyverun.h
  head/usr.sbin/bhyve/mptbl.c
  head/usr.sbin/bhyve/pci_hostbridge.c
  head/usr.sbin/bhyve/pci_virtio_block.c
  head/usr.sbin/bhyve/pci_virtio_net.c
  head/usr.sbin/bhyve/rtc.c

Modified: head/usr.sbin/bhyve/bhyverun.c
==============================================================================
--- head/usr.sbin/bhyve/bhyverun.c	Thu Oct 17 22:00:35 2013	(r256710)
+++ head/usr.sbin/bhyve/bhyverun.c	Thu Oct 17 22:01:17 2013	(r256711)
@@ -81,6 +81,7 @@ int guest_ncpus;
 
 static int pincpu = -1;
 static int guest_vmexit_on_hlt, guest_vmexit_on_pause, disable_x2apic;
+static int virtio_msix = 1;
 
 static int foundcpus;
 
@@ -120,7 +121,7 @@ usage(int code)
 {
 
         fprintf(stderr,
-                "Usage: %s [-aehAHIP][-g <gdb port>][-s <pci>][-S <pci>]"
+                "Usage: %s [-aehAHIPW][-g <gdb port>][-s <pci>][-S <pci>]"
 		"[-c vcpus][-p pincpu][-m mem]"
 		" <vmname>\n"
 		"       -a: local apic is in XAPIC mode (default is X2APIC)\n"
@@ -131,6 +132,7 @@ usage(int code)
 		"       -H: vmexit from the guest on hlt\n"
 		"       -I: present an ioapic to the guest\n"
 		"       -P: vmexit from the guest on pause\n"
+		"	-W: force virtio to use single-vector MSI\n"
 		"	-e: exit on unhandled i/o access\n"
 		"       -h: help\n"
 		"       -s: <slot,driver,configinfo> PCI slot config\n"
@@ -169,6 +171,13 @@ fbsdrun_vmexit_on_hlt(void)
 	return (guest_vmexit_on_hlt);
 }
 
+int
+fbsdrun_virtio_msix(void)
+{
+
+	return (virtio_msix);
+}
+
 static void *
 fbsdrun_start_thread(void *param)
 {
@@ -544,7 +553,7 @@ main(int argc, char *argv[])
 	ioapic = 0;
 	memsize = 256 * MB;
 
-	while ((c = getopt(argc, argv, "abehAHIPp:g:c:s:S:m:")) != -1) {
+	while ((c = getopt(argc, argv, "abehAHIPWp:g:c:s:S:m:")) != -1) {
 		switch (c) {
 		case 'a':
 			disable_x2apic = 1;
@@ -591,6 +600,9 @@ main(int argc, char *argv[])
 		case 'e':
 			strictio = 1;
 			break;
+		case 'W':
+			virtio_msix = 0;
+			break;
 		case 'h':
 			usage(0);			
 		default:

Modified: head/usr.sbin/bhyve/bhyverun.h
==============================================================================
--- head/usr.sbin/bhyve/bhyverun.h	Thu Oct 17 22:00:35 2013	(r256710)
+++ head/usr.sbin/bhyve/bhyverun.h	Thu Oct 17 22:01:17 2013	(r256711)
@@ -47,4 +47,5 @@ int  fbsdrun_muxed(void);
 int  fbsdrun_vmexit_on_hlt(void);
 int  fbsdrun_vmexit_on_pause(void);
 int  fbsdrun_disable_x2apic(void);
+int  fbsdrun_virtio_msix(void);
 #endif

Modified: head/usr.sbin/bhyve/mptbl.c
==============================================================================
--- head/usr.sbin/bhyve/mptbl.c	Thu Oct 17 22:00:35 2013	(r256710)
+++ head/usr.sbin/bhyve/mptbl.c	Thu Oct 17 22:01:17 2013	(r256711)
@@ -71,6 +71,9 @@ __FBSDID("$FreeBSD$");
 
 #define MPEP_FEATURES           (0xBFEBFBFF) /* XXX Intel i7 */
 
+/* Number of i/o intr entries */
+#define	MPEII_MAX_IRQ		16
+
 /* Define processor entry struct since <x86/mptable.h> gets it wrong */
 typedef struct BPROCENTRY {
 	u_char		type;
@@ -155,14 +158,14 @@ mpt_build_bus_entries(bus_entry_ptr mpeb
 
 	memset(mpeb, 0, sizeof(*mpeb));
 	mpeb->type = MPCT_ENTRY_BUS;
-	mpeb->bus_id = ISA;
-	memcpy(mpeb->bus_type, MPE_BUSNAME_ISA, MPE_BUSNAME_LEN);
+	mpeb->bus_id = 0;
+	memcpy(mpeb->bus_type, MPE_BUSNAME_PCI, MPE_BUSNAME_LEN);
 	mpeb++;
 
 	memset(mpeb, 0, sizeof(*mpeb));
 	mpeb->type = MPCT_ENTRY_BUS;
-	mpeb->bus_id = PCI;
-	memcpy(mpeb->bus_type, MPE_BUSNAME_PCI, MPE_BUSNAME_LEN);
+	mpeb->bus_id = 1;	
+	memcpy(mpeb->bus_type, MPE_BUSNAME_ISA, MPE_BUSNAME_LEN);
 }
 
 static void
@@ -177,9 +180,8 @@ mpt_build_ioapic_entries(io_apic_entry_p
 	mpei->apic_address = IOAPIC_PADDR;
 }
 
-#ifdef notyet
 static void
-mpt_build_ioint_entries(struct mpe_ioint *mpeii, int num_pins, int id)
+mpt_build_ioint_entries(int_entry_ptr mpie, int num_pins, int id)
 {
 	int pin;
 
@@ -189,28 +191,27 @@ mpt_build_ioint_entries(struct mpe_ioint
 	 * just use the default config, tweek later if needed.
 	 */
 
-
 	/* Run through all 16 pins. */
 	for (pin = 0; pin < num_pins; pin++) {
-		memset(mpeii, 0, sizeof(*mpeii));
-		mpeii->entry_type = MP_ENTRY_IOINT;
-		mpeii->src_bus_id = MPE_BUSID_ISA;
-		mpeii->dst_apic_id = id;
+		memset(mpie, 0, sizeof(*mpie));
+		mpie->type = MPCT_ENTRY_INT;
+		mpie->src_bus_id = 1;
+		mpie->dst_apic_id = id;
 
 		/*
 		 * All default configs route IRQs from bus 0 to the first 16
 		 * pins of the first I/O APIC with an APIC ID of 2.
 		 */
-		mpeii->dst_apic_intin = pin;
+		mpie->dst_apic_int = pin;
 		switch (pin) {
 		case 0:
 			/* Pin 0 is an ExtINT pin. */
-			mpeii->intr_type = MPEII_INTR_EXTINT;
+			mpie->int_type = INTENTRY_TYPE_EXTINT;
 			break;
 		case 2:
 			/* IRQ 0 is routed to pin 2. */
-			mpeii->intr_type = MPEII_INTR_INT;
-			mpeii->src_bus_irq = 0;
+			mpie->int_type = INTENTRY_TYPE_INT;
+			mpie->src_bus_irq = 0;
 			break;
 		case 5:
 		case 10:
@@ -218,118 +219,20 @@ mpt_build_ioint_entries(struct mpe_ioint
 			/*
 			 * PCI Irqs set to level triggered.
 			 */
-			mpeii->intr_flags = MPEII_FLAGS_TRIGMODE_LEVEL;
-			mpeii->src_bus_id = MPE_BUSID_PCI;
+			mpie->int_flags = INTENTRY_FLAGS_TRIGGER_LEVEL;
+			mpie->src_bus_id = 0;
+			/* fall through.. */
 		default:
 			/* All other pins are identity mapped. */
-			mpeii->intr_type = MPEII_INTR_INT;
-			mpeii->src_bus_irq = pin;
+			mpie->int_type = INTENTRY_TYPE_INT;
+			mpie->src_bus_irq = pin;
 			break;
 		}
-		mpeii++;
+		mpie++;
 	}
 
 }
 
-#define COPYSTR(dest, src, bytes)		\
-	memcpy(dest, src, bytes); 		\
-	str[bytes] = 0;
-
-static void
-mptable_dump(struct mp_floating_pointer *mpfp, struct mp_config_hdr *mpch)
-{
-	static char 	 str[16];
-	int 		 i;
-	char 		*cur;
-
-	union mpe {
-		struct mpe_proc 	*proc;
-		struct mpe_bus  	*bus;
-		struct mpe_ioapic 	*ioapic;
-		struct mpe_ioint 	*ioint;
-		struct mpe_lint 	*lnit;
-		char   			*p;
-	};
-
-	union mpe mpe;
-
-	printf(" MP Floating Pointer :\n");
-	COPYSTR(str, mpfp->signature, 4);
-	printf("\tsignature:\t%s\n", str);
-	printf("\tmpch paddr:\t%x\n", mpfp->mptable_paddr);
-	printf("\tlength:\t%x\n", mpfp->length);
-	printf("\tspecrec:\t%x\n", mpfp->specrev);
-	printf("\tchecksum:\t%x\n", mpfp->checksum);
-	printf("\tfeature1:\t%x\n", mpfp->feature1);
-	printf("\tfeature2:\t%x\n", mpfp->feature2);
-	printf("\tfeature3:\t%x\n", mpfp->feature3);
-	printf("\tfeature4:\t%x\n", mpfp->feature4);
-
-	printf(" MP Configuration Header :\n");
-	COPYSTR(str, mpch->signature, 4);
-	printf("    signature: 		%s\n", str);
-	printf("    length: 		%x\n", mpch->length);
-	printf("    specrec: 		%x\n", mpch->specrev);
-	printf("    checksum: 		%x\n", mpch->checksum);
-	COPYSTR(str, mpch->oemid, MPCH_OEMID_LEN);
-	printf("    oemid: 		%s\n", str);
-	COPYSTR(str, mpch->prodid, MPCH_PRODID_LEN);
-	printf("    prodid: 		%s\n", str);
-	printf("    oem_ptr: 		%x\n", mpch->oem_ptr);
-	printf("    oem_sz: 		%x\n", mpch->oem_sz);
-	printf("    nr_entries: 	%x\n", mpch->nr_entries);
-	printf("    apic paddr: 	%x\n", mpch->lapic_paddr);
-	printf("    ext_length: 	%x\n", mpch->ext_length);
-	printf("    ext_checksum: 	%x\n", mpch->ext_checksum);
-
-	cur = (char *)mpch + sizeof(*mpch);
-	for (i = 0; i < mpch->nr_entries; i++) {
-		mpe.p = cur;
-		switch(*mpe.p) {		
-			case MP_ENTRY_PROC:
-				printf(" MP Processor Entry :\n");
-				printf("	lapic_id: 	%x\n", mpe.proc->lapic_id);
-				printf("	lapic_version:	%x\n", mpe.proc->lapic_version);
-				printf("	proc_flags: 	%x\n", mpe.proc->proc_flags);
-				printf("	proc_signature: %x\n", mpe.proc->proc_signature);
-				printf("	feature_flags: 	%x\n", mpe.proc->feature_flags);
-				cur += sizeof(struct mpe_proc);
-				break;
-			case MP_ENTRY_BUS:
-				printf(" MP Bus Entry :\n");
-				printf("	busid: 		%x\n", mpe.bus->busid);
-				COPYSTR(str, mpe.bus->busname, MPE_BUSNAME_LEN);
-				printf("	busname: 	%s\n", str);
-				cur += sizeof(struct mpe_bus);
-				break;
-			case MP_ENTRY_IOAPIC:
-				printf(" MP IOAPIC Entry :\n");
-				printf("	ioapi_id: 		%x\n", mpe.ioapic->ioapic_id);
-				printf("	ioapi_version: 		%x\n", mpe.ioapic->ioapic_version);
-				printf("	ioapi_flags: 		%x\n", mpe.ioapic->ioapic_flags);
-				printf("	ioapi_paddr: 		%x\n", mpe.ioapic->ioapic_paddr);
-				cur += sizeof(struct mpe_ioapic);
-				break;
-			case MP_ENTRY_IOINT:
-				printf(" MP IO Interrupt Entry :\n");
-				printf("	intr_type: 		%x\n", mpe.ioint->intr_type);
-				printf("	intr_flags: 		%x\n", mpe.ioint->intr_flags);
-				printf("	src_bus_id: 		%x\n", mpe.ioint->src_bus_id);
-				printf("	src_bus_irq: 		%x\n", mpe.ioint->src_bus_irq);
-				printf("	dst_apic_id: 		%x\n", mpe.ioint->dst_apic_id);
-				printf("	dst_apic_intin:		%x\n", mpe.ioint->dst_apic_intin);
-				cur += sizeof(struct mpe_ioint);
-				break;
-			case MP_ENTRY_LINT:
-				printf(" MP Local Interrupt Entry :\n");
-				cur += sizeof(struct mpe_lint);
-				break;
-		}
-
-	}
-}
-#endif
-
 void
 mptable_add_oemtbl(void *tbl, int tblsz)
 {
@@ -346,6 +249,7 @@ mptable_build(struct vmctx *ctx, int ncp
 	io_apic_entry_ptr	mpei;
 	bproc_entry_ptr		mpep;
 	mpfps_t			mpfp;
+	int_entry_ptr		mpie;
 	char 			*curraddr;
 	char 			*startaddr;
 
@@ -381,12 +285,10 @@ mptable_build(struct vmctx *ctx, int ncp
 		mpch->entry_count++;
 	}
 
-#ifdef notyet
-	mpt_build_ioint_entries((struct mpe_ioint*)curraddr, MPEII_MAX_IRQ,
-				ncpu + 1);
-	curraddr += sizeof(struct mpe_ioint) * MPEII_MAX_IRQ;
+	mpie = (int_entry_ptr) curraddr;
+	mpt_build_ioint_entries(mpie, MPEII_MAX_IRQ, ncpu + 1);
+	curraddr += sizeof(*mpie) * MPEII_MAX_IRQ;
 	mpch->entry_count += MPEII_MAX_IRQ;
-#endif
 
 	if (oem_tbl_start) {
 		mpch->oem_table_pointer = curraddr - startaddr + MPTABLE_BASE;

Modified: head/usr.sbin/bhyve/pci_hostbridge.c
==============================================================================
--- head/usr.sbin/bhyve/pci_hostbridge.c	Thu Oct 17 22:00:35 2013	(r256710)
+++ head/usr.sbin/bhyve/pci_hostbridge.c	Thu Oct 17 22:01:17 2013	(r256711)
@@ -47,6 +47,22 @@ pci_hostbridge_init(struct vmctx *ctx, s
 	return (0);
 }
 
+static int
+pci_amd_hostbridge_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
+{
+	(void) pci_hostbridge_init(ctx, pi, opts);
+	pci_set_cfgdata16(pi, PCIR_VENDOR, 0x1022);	/* AMD */
+	pci_set_cfgdata16(pi, PCIR_DEVICE, 0x7432);	/* made up */
+
+	return (0);
+}
+
+struct pci_devemu pci_de_amd_hostbridge = {
+	.pe_emu = "amd_hostbridge",
+	.pe_init = pci_amd_hostbridge_init,
+};
+PCI_EMUL_SET(pci_de_amd_hostbridge);
+
 struct pci_devemu pci_de_hostbridge = {
 	.pe_emu = "hostbridge",
 	.pe_init = pci_hostbridge_init,

Modified: head/usr.sbin/bhyve/pci_virtio_block.c
==============================================================================
--- head/usr.sbin/bhyve/pci_virtio_block.c	Thu Oct 17 22:00:35 2013	(r256710)
+++ head/usr.sbin/bhyve/pci_virtio_block.c	Thu Oct 17 22:01:17 2013	(r256711)
@@ -256,8 +256,6 @@ pci_vtblk_init(struct vmctx *ctx, struct
 	off_t size;	
 	int fd;
 	int sectsz;
-	int use_msix;
-	const char *env_msi;
 
 	if (opts == NULL) {
 		printf("virtio-block: backing device required\n");
@@ -336,12 +334,7 @@ pci_vtblk_init(struct vmctx *ctx, struct
 	pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_STORAGE);
 	pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_TYPE_BLOCK);
 
-	use_msix = 1;
-	if ((env_msi = getenv("BHYVE_USE_MSI"))) {
-		if (strcasecmp(env_msi, "yes") == 0)
-			use_msix = 0;
-	} 
-	if (vi_intr_init(&sc->vbsc_vs, 1, use_msix))
+	if (vi_intr_init(&sc->vbsc_vs, 1, fbsdrun_virtio_msix()))
 		return (1);
 	vi_set_io_bar(&sc->vbsc_vs, 0);
 	return (0);

Modified: head/usr.sbin/bhyve/pci_virtio_net.c
==============================================================================
--- head/usr.sbin/bhyve/pci_virtio_net.c	Thu Oct 17 22:00:35 2013	(r256710)
+++ head/usr.sbin/bhyve/pci_virtio_net.c	Thu Oct 17 22:01:17 2013	(r256711)
@@ -509,11 +509,9 @@ pci_vtnet_init(struct vmctx *ctx, struct
 	char nstr[80];
 	char tname[MAXCOMLEN + 1];
 	struct pci_vtnet_softc *sc;
-	const char *env_msi;
 	char *devname;
 	char *vtopts;
 	int mac_provided;
-	int use_msix;
 
 	sc = malloc(sizeof(struct pci_vtnet_softc));
 	memset(sc, 0, sizeof(struct pci_vtnet_softc));
@@ -531,15 +529,6 @@ pci_vtnet_init(struct vmctx *ctx, struct
 #endif
  
 	/*
-	 * Use MSI if set by user
-	 */
-	use_msix = 1;
-	if ((env_msi = getenv("BHYVE_USE_MSI")) != NULL) {
-		if (strcasecmp(env_msi, "yes") == 0)
-			use_msix = 0;
-	}
-
-	/*
 	 * Attempt to open the tap device and read the MAC address
 	 * if specified
 	 */
@@ -623,7 +612,7 @@ pci_vtnet_init(struct vmctx *ctx, struct
 	sc->vsc_config.status = 1;
 	
 	/* use BAR 1 to map MSI-X table and PBA, if we're using MSI-X */
-	if (vi_intr_init(&sc->vsc_vs, 1, use_msix))
+	if (vi_intr_init(&sc->vsc_vs, 1, fbsdrun_virtio_msix()))
 		return (1);
 
 	/* use BAR 0 to map config regs in IO space */

Modified: head/usr.sbin/bhyve/rtc.c
==============================================================================
--- head/usr.sbin/bhyve/rtc.c	Thu Oct 17 22:00:35 2013	(r256710)
+++ head/usr.sbin/bhyve/rtc.c	Thu Oct 17 22:01:17 2013	(r256711)
@@ -331,7 +331,7 @@ rtc_init(struct vmctx *ctx)
 
 	memset(rtc_nvram, 0, sizeof(rtc_nvram));
 
-	rtc_nvram[nvoff(RTC_CENTURY)] = rtcout(tm.tm_year / 100);
+	rtc_nvram[nvoff(RTC_CENTURY)] = bin2bcd((tm.tm_year + 1900) / 100);
 
 	/* XXX init diag/reset code/equipment/checksum ? */
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201310172201.r9HM1HCf073642>