[PATCH] cardbus and pccard on old laptop
Andrew Belashov
bel at orel.ru
Sun Sep 12 01:12:10 PDT 2004
This patch resolves two separate problem:
o Incorrect programing memory map registers in exca driver.
o Memory allocation problem in cbb and pcib.
Patch tested on my old Fujitsu FMV-BIBLIO NU13 (Pentium I @133MHz).
--
With best regards,
Andrew Belashov.
-------------- next part --------------
--- dev/exca/exca.c.orig Mon Aug 16 05:57:06 2004
+++ dev/exca/exca.c Thu Sep 9 15:26:12 2004
@@ -180,9 +180,12 @@
{
struct mem_map_index_st *map;
struct pccard_mem_handle *mem;
+ uint32_t offset;
map = &mem_map_index[win];
mem = &sc->mem[win];
+ offset = ((mem->cardaddr >> EXCA_CARDMEM_ADDRX_SHIFT) -
+ (mem->addr >> EXCA_SYSMEM_ADDRX_SHIFT)) & 0x3fff;
exca_putb(sc, map->sysmem_start_lsb,
(mem->addr >> EXCA_SYSMEM_ADDRX_SHIFT) & 0xff);
exca_putb(sc, map->sysmem_start_msb,
@@ -202,9 +205,9 @@
(mem->addr >> EXCA_MEMREG_WIN_SHIFT) & 0xff);
exca_putb(sc, map->cardmem_lsb,
- (mem->cardaddr >> EXCA_CARDMEM_ADDRX_SHIFT) & 0xff);
+ offset & 0xff);
exca_putb(sc, map->cardmem_msb,
- ((mem->cardaddr >> (EXCA_CARDMEM_ADDRX_SHIFT + 8)) &
+ ((offset >> 8) &
EXCA_CARDMEM_ADDRX_MSB_ADDR_MASK) |
((mem->kind == PCCARD_A_MEM_ATTR) ?
EXCA_CARDMEM_ADDRX_MSB_REGACTIVE_ATTR : 0));
--- dev/pccbb/pccbb_pci.c.orig Mon Aug 16 10:33:58 2004
+++ dev/pccbb/pccbb_pci.c Sun Sep 12 10:50:03 2004
@@ -286,6 +286,41 @@
printf("\n");
}
+extern u_long cbb_start_mem;
+
+static int
+cbb_pci_get_memory(device_t brdev, int *rid)
+{
+ struct cbb_softc *sc;
+ u_int32_t sockbase;
+
+ sc = (struct cbb_softc *) device_get_softc(brdev);
+ sockbase = pci_read_config(brdev, *rid, 4);
+ if (sockbase >= 0x100000 && sockbase < 0xfffffff0) {
+ device_printf(brdev, "Could not map register memory 0x%x\n",
+ sockbase);
+ return (ENOMEM);
+ }
+ pci_write_config(brdev, *rid, 0xffffffff, 4);
+ sockbase = pci_read_config(brdev, *rid, 4);
+ sockbase = (sockbase & 0xfffffff0) & -(sockbase & 0xfffffff0);
+#define CBB_SYS_RES_MEMORY_END 0xFFFFFFFF
+ sc->base_res = bus_generic_alloc_resource(device_get_parent(brdev),
+ brdev, SYS_RES_MEMORY, rid,
+ cbb_start_mem, CBB_SYS_RES_MEMORY_END,
+ sockbase, RF_ACTIVE | rman_make_alignment_flags(sockbase));
+ if (sc->base_res == NULL) {
+ device_printf(brdev, "Could not grab register memory\n");
+ return (ENOMEM);
+ }
+ sockbase = rman_get_start(sc->base_res);
+ pci_write_config(brdev, *rid, sockbase, 4);
+#if 1
+ device_printf(brdev, "Fixup pcib bug: PCI Memory allocated: 0x%08x\n", sockbase);
+#endif
+ return (0);
+}
+
static int
cbb_pci_attach(device_t brdev)
{
@@ -312,6 +347,18 @@
rid = CBBR_SOCKBASE;
sc->base_res = bus_alloc_resource_any(brdev, SYS_RES_MEMORY, &rid,
RF_ACTIVE);
+
+ /*
+ * XXX Here temp(?) workaround for systems with resource allocation
+ * problem. Fixup resource allocation bug/feature in pcib.
+ */
+ if (sc->base_res && rman_get_start(sc->base_res) < 0x100000) {
+ bus_release_resource(brdev, SYS_RES_MEMORY, rid,
+ sc->base_res);
+ sc->base_res = NULL;
+ cbb_pci_get_memory(brdev, &rid);
+ }
+
if (!sc->base_res) {
device_printf(brdev, "Could not map register memory\n");
mtx_destroy(&sc->mtx);
More information about the freebsd-mobile
mailing list