Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/pci/vga_pci.c
| Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
| }; | }; | ||||
| SYSCTL_DECL(_hw_pci); | SYSCTL_DECL(_hw_pci); | ||||
| static struct vga_resource *lookup_res(struct vga_pci_softc *sc, int rid); | static struct vga_resource *lookup_res(struct vga_pci_softc *sc, int rid); | ||||
| static struct resource *vga_pci_alloc_resource(device_t dev, device_t child, | static struct resource *vga_pci_alloc_resource(device_t dev, device_t child, | ||||
| int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, | int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, | ||||
| u_int flags); | u_int flags); | ||||
| static int vga_pci_release_resource(device_t dev, device_t child, int type, | static int vga_pci_release_resource(device_t dev, device_t child, | ||||
| int rid, struct resource *r); | struct resource *r); | ||||
| int vga_pci_default_unit = -1; | int vga_pci_default_unit = -1; | ||||
| SYSCTL_INT(_hw_pci, OID_AUTO, default_vgapci_unit, CTLFLAG_RDTUN, | SYSCTL_INT(_hw_pci, OID_AUTO, default_vgapci_unit, CTLFLAG_RDTUN, | ||||
| &vga_pci_default_unit, -1, "Default VGA-compatible display"); | &vga_pci_default_unit, -1, "Default VGA-compatible display"); | ||||
| int | int | ||||
| vga_pci_is_boot_display(device_t dev) | vga_pci_is_boot_display(device_t dev) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | #endif | ||||
| * Enable ROM decode | * Enable ROM decode | ||||
| */ | */ | ||||
| vga_pci_reset(dev); | vga_pci_reset(dev); | ||||
| rom_addr = pci_read_config(dev, rid, 4); | rom_addr = pci_read_config(dev, rid, 4); | ||||
| rom_addr &= 0x7ff; | rom_addr &= 0x7ff; | ||||
| rom_addr |= rman_get_start(res) | 0x1; | rom_addr |= rman_get_start(res) | 0x1; | ||||
| pci_write_config(dev, rid, rom_addr, 4); | pci_write_config(dev, rid, rom_addr, 4); | ||||
| vr = lookup_res(device_get_softc(dev), rid); | vr = lookup_res(device_get_softc(dev), rid); | ||||
| vga_pci_release_resource(dev, NULL, SYS_RES_MEMORY, rid, | vga_pci_release_resource(dev, NULL, vr->vr_res); | ||||
| vr->vr_res); | |||||
| /* | /* | ||||
| * re-allocate | * re-allocate | ||||
| */ | */ | ||||
| res = vga_pci_alloc_resource(dev, NULL, SYS_RES_MEMORY, &rid, 0, | res = vga_pci_alloc_resource(dev, NULL, SYS_RES_MEMORY, &rid, 0, | ||||
| ~0, 1, RF_ACTIVE); | ~0, 1, RF_ACTIVE); | ||||
| if (res == NULL) { | if (res == NULL) { | ||||
| device_printf(dev, "vga_pci_alloc_resource failed\n"); | device_printf(dev, "vga_pci_alloc_resource failed\n"); | ||||
| return (NULL); | return (NULL); | ||||
| } | } | ||||
| bios = rman_get_virtual(res); | bios = rman_get_virtual(res); | ||||
| *size = rman_get_size(res); | *size = rman_get_size(res); | ||||
| for (found = i = 0; i < 3*hz; i++) { | for (found = i = 0; i < 3*hz; i++) { | ||||
| found = (bios[0] == 0x55 && bios[1] == 0xaa); | found = (bios[0] == 0x55 && bios[1] == 0xaa); | ||||
| if (found) | if (found) | ||||
| break; | break; | ||||
| pause("vgabios", 1); | pause("vgabios", 1); | ||||
| } | } | ||||
| if (found) | if (found) | ||||
| return (__DEVOLATILE(void *, bios)); | return (__DEVOLATILE(void *, bios)); | ||||
| device_printf(dev, "ROM mapping failed\n"); | device_printf(dev, "ROM mapping failed\n"); | ||||
| vr = lookup_res(device_get_softc(dev), rid); | vr = lookup_res(device_get_softc(dev), rid); | ||||
| vga_pci_release_resource(dev, NULL, SYS_RES_MEMORY, rid, | vga_pci_release_resource(dev, NULL, vr->vr_res); | ||||
| vr->vr_res); | |||||
| return (NULL); | return (NULL); | ||||
| } | } | ||||
| void | void | ||||
| vga_pci_unmap_bios(device_t dev, void *bios) | vga_pci_unmap_bios(device_t dev, void *bios) | ||||
| { | { | ||||
| struct vga_resource *vr; | struct vga_resource *vr; | ||||
| int rid; | int rid; | ||||
| Show All 26 Lines | #endif | ||||
| /* | /* | ||||
| * Look up the PCIR_BIOS resource in our softc. It should match | * Look up the PCIR_BIOS resource in our softc. It should match | ||||
| * the address we returned previously. | * the address we returned previously. | ||||
| */ | */ | ||||
| vr = lookup_res(device_get_softc(dev), rid); | vr = lookup_res(device_get_softc(dev), rid); | ||||
| KASSERT(vr->vr_res != NULL, ("vga_pci_unmap_bios: bios not mapped")); | KASSERT(vr->vr_res != NULL, ("vga_pci_unmap_bios: bios not mapped")); | ||||
| KASSERT(rman_get_virtual(vr->vr_res) == bios, | KASSERT(rman_get_virtual(vr->vr_res) == bios, | ||||
| ("vga_pci_unmap_bios: mismatch")); | ("vga_pci_unmap_bios: mismatch")); | ||||
| vga_pci_release_resource(dev, NULL, SYS_RES_MEMORY, rid, | vga_pci_release_resource(dev, NULL, vr->vr_res); | ||||
| vr->vr_res); | |||||
| } | } | ||||
| int | int | ||||
| vga_pci_repost(device_t dev) | vga_pci_repost(device_t dev) | ||||
| { | { | ||||
| #if defined(__amd64__) || defined(__i386__) | #if defined(__amd64__) || defined(__i386__) | ||||
| x86regs_t regs; | x86regs_t regs; | ||||
| ▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | case SYS_RES_IOPORT: | ||||
| if (vr->vr_res != NULL) | if (vr->vr_res != NULL) | ||||
| vr->vr_refs++; | vr->vr_refs++; | ||||
| return (vr->vr_res); | return (vr->vr_res); | ||||
| } | } | ||||
| return (bus_alloc_resource(dev, type, rid, start, end, count, flags)); | return (bus_alloc_resource(dev, type, rid, start, end, count, flags)); | ||||
| } | } | ||||
| static int | static int | ||||
| vga_pci_release_resource(device_t dev, device_t child, int type, int rid, | vga_pci_release_resource(device_t dev, device_t child, struct resource *r) | ||||
| struct resource *r) | |||||
| { | { | ||||
| struct vga_resource *vr; | struct vga_resource *vr; | ||||
| int error; | int error; | ||||
| switch (type) { | switch (rman_get_type(r)) { | ||||
| case SYS_RES_MEMORY: | case SYS_RES_MEMORY: | ||||
| case SYS_RES_IOPORT: | case SYS_RES_IOPORT: | ||||
| /* | /* | ||||
| * For BARs, we release the resource from the PCI bus | * For BARs, we release the resource from the PCI bus | ||||
| * when the last child reference goes away. | * when the last child reference goes away. | ||||
| */ | */ | ||||
| vr = lookup_res(device_get_softc(dev), rid); | vr = lookup_res(device_get_softc(dev), rman_get_rid(r)); | ||||
| if (vr == NULL) | if (vr == NULL) | ||||
| return (EINVAL); | return (EINVAL); | ||||
| if (vr->vr_res == NULL) | if (vr->vr_res == NULL) | ||||
| return (EINVAL); | return (EINVAL); | ||||
| KASSERT(vr->vr_res == r, ("vga_pci resource mismatch")); | KASSERT(vr->vr_res == r, ("vga_pci resource mismatch")); | ||||
| if (vr->vr_refs > 1) { | if (vr->vr_refs > 1) { | ||||
| vr->vr_refs--; | vr->vr_refs--; | ||||
| return (0); | return (0); | ||||
| } | } | ||||
| KASSERT(vr->vr_refs > 0, | KASSERT(vr->vr_refs > 0, | ||||
| ("vga_pci resource reference count underflow")); | ("vga_pci resource reference count underflow")); | ||||
| error = bus_release_resource(dev, type, rid, r); | error = bus_release_resource(dev, r); | ||||
| if (error == 0) { | if (error == 0) { | ||||
| vr->vr_res = NULL; | vr->vr_res = NULL; | ||||
| vr->vr_refs = 0; | vr->vr_refs = 0; | ||||
| } | } | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| return (bus_release_resource(dev, type, rid, r)); | return (bus_release_resource(dev, r)); | ||||
| } | } | ||||
| /* PCI interface. */ | /* PCI interface. */ | ||||
| static uint32_t | static uint32_t | ||||
| vga_pci_read_config(device_t dev, device_t child, int reg, int width) | vga_pci_read_config(device_t dev, device_t child, int reg, int width) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 266 Lines • Show Last 20 Lines | |||||