Hi,

Those 2 patches by Mark Kettenis have been shipped into OpenBSD's version
of libpciaccess for more than one year. Before we start adapting the 
VGA legacy stuff, I'd like to push them...

>From 5135046bb3d59b0156cd4b79a8ed344da82d2c3e Mon Sep 17 00:00:00 2001
From: Mark Kettenis <[email protected]>
Date: Sun, 6 Nov 2011 17:32:51 +0000
Subject: [PATCH libpciaccess 1/2] OpenBSD: Indicate that devices need access
 to legacy VGA resources.

Makes sure xserver disables DRI if the VGA arbiter is in use.

Signed-off-by: Matthieu Herrb <[email protected]>
---
 src/openbsd_pci.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/src/openbsd_pci.c b/src/openbsd_pci.c
index e954144..b5559ad 100644
--- a/src/openbsd_pci.c
+++ b/src/openbsd_pci.c
@@ -505,6 +505,10 @@ pci_system_openbsd_create(void)
                                        device->base.subvendor_id = 
PCI_VENDOR(reg);
                                        device->base.subdevice_id = 
PCI_PRODUCT(reg);
 
+                                       device->base.vgaarb_rsrc =
+                                           VGA_ARB_RSRC_LEGACY_IO |
+                                           VGA_ARB_RSRC_LEGACY_MEM;
+
                                        device++;
                                }
                        }
-- 
1.7.6

>From 88e49310e8cd68ab8505b3a516c69d824746b63c Mon Sep 17 00:00:00 2001
From: Mark Kettenis <[email protected]>
Date: Sun, 6 Nov 2011 17:34:29 +0000
Subject: [PATCH libpciaccess 2/2] Add VGA Arbiter support for OpenBSD.

Signed-off-by: Matthieu Herrb <[email protected]>
---
 src/Makefile.am   |   10 ++--
 src/openbsd_pci.c |  134 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+), 5 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 6757a6f..13a7d94 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,32 +28,32 @@ lib_LTLIBRARIES = libpciaccess.la
 
 if LINUX
 OS_SUPPORT = linux_sysfs.c linux_devmem.c linux_devmem.h
+VGA_ARBITER = common_vgaarb.c
 endif
 
 if FREEBSD
 OS_SUPPORT = freebsd_pci.c
+VGA_ARBITER = common_vgaarb_stub.c
 endif
 
 if NETBSD
 OS_SUPPORT = netbsd_pci.c
+VGA_ARBITER = common_vgaarb_stub.c
 endif
 
 if OPENBSD
 OS_SUPPORT = openbsd_pci.c
+# VGA Arbiter code is included in openbsd_pci.c
 endif
 
 if SOLARIS
 OS_SUPPORT = solx_devfs.c pci_tools.h
-endif
-
-if LINUX
-VGA_ARBITER = common_vgaarb.c
-else
 VGA_ARBITER = common_vgaarb_stub.c
 endif
 
 if GNU
 OS_SUPPORT = x86_pci.c
+VGA_ARBITER = common_vgaarb_stub.c
 endif
 
 libpciaccess_la_SOURCES = common_bridge.c \
diff --git a/src/openbsd_pci.c b/src/openbsd_pci.c
index b5559ad..219aba7 100644
--- a/src/openbsd_pci.c
+++ b/src/openbsd_pci.c
@@ -523,3 +523,137 @@ pci_system_openbsd_init_dev_mem(int fd)
 {
        aperturefd = fd;
 }
+
+int
+pci_device_vgaarb_init(void)
+{
+       struct pci_device *dev = pci_sys->vga_target;
+       struct pci_device_iterator *iter;
+       struct pci_id_match vga_match = {
+               PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
+               (PCI_CLASS_DISPLAY << 16) | (PCI_SUBCLASS_DISPLAY_VGA << 8),
+               0x00ffff00
+       };
+       struct pci_vga pv;
+       int err;
+
+       pv.pv_sel.pc_bus = 0;
+       pv.pv_sel.pc_dev = 0;
+       pv.pv_sel.pc_func = 0;
+       err = ioctl(pcifd[0], PCIOCGETVGA, &pv);
+       if (err)
+               return err;
+
+       pci_sys->vga_target = pci_device_find_by_slot(0, pv.pv_sel.pc_bus,
+           pv.pv_sel.pc_dev, pv.pv_sel.pc_func);
+
+       /* Count the number of VGA devices in domain 0. */
+       iter = pci_id_match_iterator_create(&vga_match);
+       if (iter == NULL)
+               return -1;
+       pci_sys->vga_count = 0;
+       while ((dev = pci_device_next(iter)) != NULL) {
+               if (dev->domain == 0)
+                       pci_sys->vga_count++;
+       }
+       pci_iterator_destroy(iter);
+
+       return 0;
+}
+
+void
+pci_device_vgaarb_fini(void)
+{
+       struct pci_device *dev;
+       struct pci_vga pv;
+
+       if (pci_sys == NULL)
+               return;
+       dev = pci_sys->vga_target;
+       if (dev == NULL)
+               return;
+
+       pv.pv_sel.pc_bus = dev->bus;
+       pv.pv_sel.pc_dev = dev->dev;
+       pv.pv_sel.pc_func = dev->func;
+       pv.pv_lock = PCI_VGA_UNLOCK;
+       ioctl(pcifd[dev->domain], PCIOCSETVGA, &pv);
+}
+
+int
+pci_device_vgaarb_set_target(struct pci_device *dev)
+{
+       pci_sys->vga_target = dev;
+}
+
+int
+pci_device_vgaarb_lock(void)
+{
+       struct pci_device *dev = pci_sys->vga_target;
+       struct pci_vga pv;
+
+       if (dev == NULL)
+               return -1;
+
+#if 0
+       if (dev->vgaarb_rsrc == 0 || pci_sys->vga_count == 1)
+               return 0;
+#else
+       if (pci_sys->vga_count == 1)
+               return 0;
+#endif
+
+       pv.pv_sel.pc_bus = dev->bus;
+       pv.pv_sel.pc_dev = dev->dev;
+       pv.pv_sel.pc_func = dev->func;
+       pv.pv_lock = PCI_VGA_LOCK;
+       return ioctl(pcifd[dev->domain], PCIOCSETVGA, &pv);
+}
+
+int
+pci_device_vgaarb_unlock(void)
+{
+       struct pci_device *dev = pci_sys->vga_target;
+       struct pci_vga pv;
+
+       if (dev == NULL)
+               return -1;
+
+#if 0
+       if (dev->vgaarb_rsrc == 0 || pci_sys->vga_count == 1)
+               return 0;
+#else
+       if (pci_sys->vga_count == 1)
+               return 0;
+#endif
+
+       pv.pv_sel.pc_bus = dev->bus;
+       pv.pv_sel.pc_dev = dev->dev;
+       pv.pv_sel.pc_func = dev->func;
+       pv.pv_lock = PCI_VGA_UNLOCK;
+       return ioctl(pcifd[dev->domain], PCIOCSETVGA, &pv);
+}
+
+int
+pci_device_vgaarb_get_info(struct pci_device *dev, int *vga_count,
+    int *rsrc_decodes)
+{
+       *vga_count = pci_sys->vga_count;
+
+       if (dev)
+               *rsrc_decodes = dev->vgaarb_rsrc;
+
+       return 0;
+}
+
+int
+pci_device_vgaarb_decodes(int rsrc_decodes)
+{
+       struct pci_device *dev = pci_sys->vga_target;
+
+       if (dev == NULL)
+               return -1;
+
+       dev->vgaarb_rsrc = rsrc_decodes;
+       return 0;
+}
-- 
1.7.6

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to