socsvn commit: r253730 - in soc2013/syuu/bhyve_usb/usr.sbin/bhyve: . usb
syuu at FreeBSD.org
syuu at FreeBSD.org
Sun Jun 30 12:46:04 UTC 2013
Author: syuu
Date: Sun Jun 30 12:46:03 2013
New Revision: 253730
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253730
Log:
initialize config space/IO space handler
Modified:
soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile
soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c
Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile
==============================================================================
--- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Sun Jun 30 12:11:34 2013 (r253729)
+++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Sun Jun 30 12:46:03 2013 (r253730)
@@ -16,7 +16,7 @@
SRCS+= vmm_instruction_emul.c
.PATH: ${.CURDIR}/usb
-CFLAGS+=-I${.CURDIR}/usb/include
+CFLAGS+=-I${.CURDIR}/usb/include -I${.CURDIR}
SRCS+= core.c hcd-uhci.c
NO_MAN=
Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c
==============================================================================
--- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Sun Jun 30 12:11:34 2013 (r253729)
+++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Sun Jun 30 12:46:03 2013 (r253730)
@@ -25,10 +25,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#include "hw/usb.h"
#include <sys/endian.h>
#include <stdlib.h>
#include <dev/pci/pcireg.h>
+#include <pthread.h>
+#include <pthread_np.h>
+#include <string.h>
+
+#include "pci_emul.h"
+#include "hw/usb.h"
#define le32_to_cpus(x) le32toh(x)
#define cpu_to_le32(x) htole32(x)
@@ -36,12 +41,15 @@
#define PCI_CLASS_PROG PCIR_PROGIF
#define PCI_VENDOR_ID_INTEL 0x8086
-#define PCI_DEVICE_ID_INTEL_82801I_UHCI3 0x2936
-#define PCI_DEVICE_ID_INTEL_82801I_UHCI4 0x2937
-#define PCI_DEVICE_ID_INTEL_82801I_UHCI5 0x2938
#define PCI_DEVICE_ID_INTEL_82801I_UHCI6 0x2939
-#define PCI_DEVICE_ID_INTEL_82371SB_2 0x7020
-#define PCI_DEVICE_ID_INTEL_82371AB_2 0x7112
+
+/*
+ * Per-device softc
+ */
+struct pci_uhci_softc {
+ struct pci_devinst *sc_pi;
+ pthread_mutex_t sc_mtx;
+};
struct PCIDevice {
uint8_t *config;
@@ -63,6 +71,9 @@
#define trace_usb_uhci_packet_add(token, td_addr) \
fprintf(stderr, "%s:%d trace_usb_uhci_packet_add token=%x td_addr=%x\n", \
__func__, __LINE__, token, td_addr)
+#define trace_usb_uhci_packet_del(token, td_addr) \
+ fprintf(stderr, "%s:%d trace_usb_uhci_packet_del token=%x td_addr=%x\n", \
+ __func__, __LINE__, token, td_addr)
#define trace_usb_uhci_packet_cancel(token, td_addr, done) \
fprintf(stderr, "%s:%d trace_usb_uhci_packet_cancel token=%x td_addr=%x done=%x\n", \
__func__, __LINE__, token, td_addr, done)
@@ -136,6 +147,9 @@
//#define DEBUG
//#define DEBUG_DUMP_DATA
+#define PCI_USBREV 0x60 /* USB protocol revision */
+#define PCI_USB_REV_1_1 0x11
+
#define UHCI_CMD_FGR (1 << 4)
#define UHCI_CMD_EGSM (1 << 3)
#define UHCI_CMD_GRESET (1 << 2)
@@ -372,7 +386,7 @@
static void uhci_async_free(UHCIAsync *async)
{
-// trace_usb_uhci_packet_del(async->queue->token, async->td_addr);
+ trace_usb_uhci_packet_del(async->queue->token, async->td_addr);
usb_packet_cleanup(&async->packet);
if (async->buf != async->static_buf) {
free(async->buf);
@@ -1520,3 +1534,64 @@
}
//type_init(uhci_register_types)
+
+static void
+pci_uhci_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi,
+ int baridx, uint64_t offset, int size, uint64_t value)
+{
+ struct pci_uhci_softc *sc = pi->pi_arg;
+
+ pthread_mutex_lock(&sc->sc_mtx);
+ printf("%s baridx:%d offset:%lx size:%d value:%lx\n", __func__, baridx, offset, size, value);
+ pthread_mutex_unlock(&sc->sc_mtx);
+}
+
+
+uint64_t
+pci_uhci_read(struct vmctx *ctx, int vcpu, struct pci_devinst *pi,
+ int baridx, uint64_t offset, int size)
+{
+ struct pci_uhci_softc *sc = pi->pi_arg;
+ uint64_t value;
+
+ pthread_mutex_lock(&sc->sc_mtx);
+ printf("%s baridx:%d offset:%lx size:%d\n", __func__, baridx, offset, size);
+ pthread_mutex_unlock(&sc->sc_mtx);
+
+ return (value);
+}
+
+static int
+pci_uhci_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
+{
+ struct pci_uhci_softc *sc;
+
+ sc = malloc(sizeof(struct pci_uhci_softc));
+ memset(sc, 0, sizeof(struct pci_uhci_softc));
+
+ pi->pi_arg = sc;
+ sc->sc_pi = pi;
+
+ pthread_mutex_init(&sc->sc_mtx, NULL);
+
+ /* initialize config space */
+ pci_set_cfgdata16(pi, PCIR_DEVICE, PCI_DEVICE_ID_INTEL_82801I_UHCI6);
+ pci_set_cfgdata16(pi, PCIR_VENDOR, PCI_VENDOR_ID_INTEL);
+ pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_SERIALBUS);
+ pci_set_cfgdata8(pi, PCI_USBREV, PCI_USB_REV_1_1);
+
+ /* MSI support */
+ pci_emul_add_msicap(pi, 1);
+
+ pci_emul_alloc_bar(pi, 4, PCIBAR_IO, 0x20);
+
+ return (0);
+}
+
+struct pci_devemu pci_hcd_uhci = {
+ .pe_emu = "hcd-uhci",
+ .pe_init = pci_uhci_init,
+ .pe_barwrite = pci_uhci_write,
+ .pe_barread = pci_uhci_read
+};
+PCI_EMUL_SET(pci_hcd_uhci);
More information about the svn-soc-all
mailing list