[PATCH 1/4] freebsd: Implement I/O port API

Adam Jackson ajax at redhat.com
Wed Sep 22 13:10:49 PDT 2010


Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 src/freebsd_pci.c |  113 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 113 insertions(+), 0 deletions(-)

diff --git a/src/freebsd_pci.c b/src/freebsd_pci.c
index 4a2dcf1..6220bb1 100644
--- a/src/freebsd_pci.c
+++ b/src/freebsd_pci.c
@@ -1,6 +1,7 @@
 /*
  * (C) Copyright Eric Anholt 2006
  * (C) Copyright IBM Corporation 2006
+ * Copyright 2010 Red Hat, Inc.
  * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -42,6 +43,9 @@
 #include <sys/pciio.h>
 #include <sys/mman.h>
 #include <sys/memrange.h>
+#include <sys/ioctl.h>
+#include <dev/io/iodev.h>
+#include <machine/iodev.h>
 
 #include "config.h"
 #include "pciaccess.h"
@@ -553,6 +557,105 @@ pci_device_freebsd_probe( struct pci_device * dev )
 
 #endif
 
+static struct pci_io_handle *
+pci_device_freebsd_open_legacy_io(struct pci_io_handle *ret,
+                                  struct pci_device *dev, pciaddr_t base,
+                                  pciaddr_t size)
+{
+    ret->fd = open("/dev/io", O_RDWR);
+
+    if (ret->fd < 0)
+	return NULL;
+
+    ret->base = base;
+    ret->size = size;
+
+    return ret;
+}
+
+static struct pci_io_handle *
+pci_device_freebsd_open_device_io(struct pci_io_handle *ret,
+                                  struct pci_device *dev, int bar,
+                                  pciaddr_t base, pciaddr_t size)
+{
+    pciaddr_t barbase, barsize;
+
+    return pci_device_freebsd_open_legacy_io(ret, dev,
+                                             dev->regions[bar].base + base,
+                                             size);
+
+}
+
+static void
+pci_device_freebsd_close_io(struct pci_device *dev,
+                            struct pci_io_handle *handle)
+{
+    close(handle->fd);
+}
+
+static u_int
+pio_read(int fd, uint32_t port, uint32_t width)
+{
+    struct iodev_pio_req req;
+
+    req.access = IODEV_PIO_READ;
+    req.port = port;
+    req.width = width;
+    ioctl(fd, IODEV_PIO, &req);
+    return req.val;
+}
+
+static uint32_t
+pci_device_freebsd_read32(struct pci_io_handle *handle, uint32_t port)
+{
+    return pio_read(handle->fd, port + handle->base, 4);
+}
+
+static uint16_t
+pci_device_freebsd_read16(struct pci_io_handle *handle, uint32_t port)
+{
+    return pio_read(handle->fd, port + handle->base, 2);
+}
+
+static uint8_t
+pci_device_freebsd_read8(struct pci_io_handle *handle, uint32_t port)
+{
+    return pio_read(handle->fd, port + handle->base, 1);
+}
+
+static void
+pio_write(int fd, uint32_t port, uint32_t width, uint32_t data)
+{
+    struct iodev_pio_req req;
+
+    req.access = IODEV_PIO_WRITE;
+    req.port = port;
+    req.width = width;
+    req.val = data;
+    ioctl(fd, IODEV_PIO, &req);
+}
+
+static void
+pci_device_freebsd_write32(struct pci_io_handle *handle, uint32_t port,
+                           uint32_t data)
+{
+    pio_write(handle->fd, port + handle->base, 4, data);
+}
+
+static void
+pci_device_freebsd_write16(struct pci_io_handle *handle, uint32_t port,
+                           uint16_t data)
+{
+    pio_write(handle->fd, port + handle->base, 2, data);
+}
+
+static void
+pci_device_freebsd_write8(struct pci_io_handle *handle, uint32_t port,
+                          uint8_t data)
+{
+    pio_write(handle->fd, port + handle->base, 1, data);
+}
+
 static void
 pci_system_freebsd_destroy(void)
 {
@@ -571,6 +674,16 @@ static const struct pci_system_methods freebsd_pci_methods = {
     .read = pci_device_freebsd_read,
     .write = pci_device_freebsd_write,
     .fill_capabilities = pci_fill_capabilities_generic,
+
+    .open_device_io = pci_device_freebsd_open_device_io,
+    .open_legacy_io = pci_device_freebsd_open_legacy_io,
+    .close_io = pci_device_freebsd_close_io,
+    .read32 = pci_device_freebsd_read32,
+    .read16 = pci_device_freebsd_read16,
+    .read8 = pci_device_freebsd_read8,
+    .write32 = pci_device_freebsd_write32,
+    .write16 = pci_device_freebsd_write16,
+    .write8 = pci_device_freebsd_write8,
 };
 
 /**
-- 
1.7.2.2



More information about the xorg-devel mailing list