aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/pci
diff options
context:
space:
mode:
authorJean-Sébastien Pédron <dumbbell@FreeBSD.org>2013-08-25 18:09:11 +0000
committerJean-Sébastien Pédron <dumbbell@FreeBSD.org>2013-08-25 18:09:11 +0000
commit509a8ff67aab9b0c84a30cb646154d9cad8b0b26 (patch)
treec6348f716e71dc6aa04d3b1344d1859307c68bc5 /sys/dev/pci
parente558c87be36e3b7414add529e0b0b38ca7ddf59a (diff)
downloadsrc-509a8ff67aab9b0c84a30cb646154d9cad8b0b26.tar.gz
src-509a8ff67aab9b0c84a30cb646154d9cad8b0b26.zip
vga_pci: Add API to map the Video BIOS
Here are two new functions to map and unmap the Video BIOS: void * vga_pci_map_bios(device_t dev, size_t *size); void vga_pci_unmap_bios(device_t dev, void *bios); The BIOS is either taken from the shadow copy made by the System BIOS at boot time if the given device was used for the default display (i386, amd64 and ia64 only), or from the PCI expansion ROM. Additionally, one can determine if a given device was the default display at boot time using the following new function: void vga_pci_unmap_bios(device_t dev, void *bios);
Notes
Notes: svn path=/head/; revision=254882
Diffstat (limited to 'sys/dev/pci')
-rw-r--r--sys/dev/pci/pcivar.h7
-rw-r--r--sys/dev/pci/vga_pci.c98
2 files changed, 105 insertions, 0 deletions
diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h
index f4c6f51007b4..d733e3b6cedf 100644
--- a/sys/dev/pci/pcivar.h
+++ b/sys/dev/pci/pcivar.h
@@ -517,4 +517,11 @@ extern uint32_t pci_generation;
struct pci_map *pci_find_bar(device_t dev, int reg);
int pci_bar_enabled(device_t dev, struct pci_map *pm);
+#define VGA_PCI_BIOS_SHADOW_ADDR 0xC0000
+#define VGA_PCI_BIOS_SHADOW_SIZE 131072
+
+int vga_pci_is_boot_display(device_t dev);
+void * vga_pci_map_bios(device_t dev, size_t *size);
+void vga_pci_unmap_bios(device_t dev, void *bios);
+
#endif /* _PCIVAR_H_ */
diff --git a/sys/dev/pci/vga_pci.c b/sys/dev/pci/vga_pci.c
index dc3237c790ea..0f3aa28e5dd7 100644
--- a/sys/dev/pci/vga_pci.c
+++ b/sys/dev/pci/vga_pci.c
@@ -46,6 +46,11 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <sys/systm.h>
+#if defined(__amd64__) || defined(__i386__) || defined(__ia64__)
+#include <vm/vm.h>
+#include <vm/pmap.h>
+#endif
+
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
@@ -67,6 +72,99 @@ TUNABLE_INT("hw.pci.default_vgapci_unit", &vga_pci_default_unit);
SYSCTL_INT(_hw_pci, OID_AUTO, default_vgapci_unit, CTLFLAG_RDTUN,
&vga_pci_default_unit, -1, "Default VGA-compatible display");
+int
+vga_pci_is_boot_display(device_t dev)
+{
+
+ /*
+ * Return true if the given device is the default display used
+ * at boot time.
+ */
+
+ return (
+ (pci_get_class(dev) == PCIC_DISPLAY ||
+ (pci_get_class(dev) == PCIC_OLD &&
+ pci_get_subclass(dev) == PCIS_OLD_VGA)) &&
+ device_get_unit(dev) == vga_pci_default_unit);
+}
+
+void *
+vga_pci_map_bios(device_t dev, size_t *size)
+{
+ int rid;
+ struct resource *res;
+
+#if defined(__amd64__) || defined(__i386__) || defined(__ia64__)
+ if (vga_pci_is_boot_display(dev)) {
+ /*
+ * On x86, the System BIOS copy the default display
+ * device's Video BIOS at a fixed location in system
+ * memory (0xC0000, 128 kBytes long) at boot time.
+ *
+ * We use this copy for the default boot device, because
+ * the original ROM may not be valid after boot.
+ */
+
+ printf("%s: Mapping BIOS shadow\n", __func__);
+ *size = VGA_PCI_BIOS_SHADOW_SIZE;
+ return (pmap_mapbios(VGA_PCI_BIOS_SHADOW_ADDR, *size));
+ }
+#endif
+
+ printf("%s: Mapping PCI expansion ROM\n", __func__);
+ rid = PCIR_BIOS;
+ res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
+ if (res == NULL) {
+ return (NULL);
+ }
+
+ *size = rman_get_size(res);
+ return (rman_get_virtual(res));
+}
+
+void
+vga_pci_unmap_bios(device_t dev, void *bios)
+{
+ int rid;
+ struct resource *res;
+
+ if (bios == NULL) {
+ return;
+ }
+
+#if defined(__amd64__) || defined(__i386__) || defined(__ia64__)
+ if (vga_pci_is_boot_display(dev)) {
+ /* We mapped the BIOS shadow copy located at 0xC0000. */
+ printf("%s: Unmapping BIOS shadow\n", __func__);
+ pmap_unmapdev((vm_offset_t)bios, VGA_PCI_BIOS_SHADOW_SIZE);
+
+ return;
+ }
+#endif
+
+ /*
+ * FIXME: We returned only the virtual address of the resource
+ * to the caller. Now, to get the resource struct back, we
+ * allocate it again: the struct exists once in memory in
+ * device softc. Therefore, we release twice now to release the
+ * reference we just obtained to get the structure back and the
+ * caller's reference.
+ */
+
+ printf("%s: Unmapping PCI expansion ROM\n", __func__);
+ rid = PCIR_BIOS;
+ res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
+
+ KASSERT(res != NULL,
+ ("%s: Can't get BIOS resource back", __func__));
+ KASSERT(bios == rman_get_virtual(res),
+ ("%s: Given BIOS address doesn't match "
+ "resource virtual address", __func__));
+
+ bus_release_resource(dev, SYS_RES_MEMORY, rid, bios);
+ bus_release_resource(dev, SYS_RES_MEMORY, rid, bios);
+}
+
static int
vga_pci_probe(device_t dev)
{