[PATCH] ToPIC95B cardbus on old laptop

Tijl Coosemans tijl at ulyssis.org
Fri Sep 10 02:55:27 PDT 2004


On Thu, 09 Sep 2004 08:35:55 +0100, Mark Murray wrote:

> Could you please post the updated, working patch to the
> freebsd-mobile@ list, with a honking great-big "[PATCH]" in the
> subject so it doesn't get lost.

Here it is. It addresses cardbus memory allocation for non-acpi
laptops.

However, as mentioned in the original patch at
<http://www.freebsd.org/cgi/query-pr.cgi?pr=66848> this might not be a
clean solution. Quoting Warner Losh:

``The real issue is that the non acpi pcib driver doesn't restrict the
memory ranges like it should, causing the allocation of 0!''

This patch adds a workarround in the cardbus driver, but the
actual problem might not be there.
-------------- next part --------------
--- sys/dev/pccbb/pccbb_pci.c.orig	Fri Sep 10 11:26:02 2004
+++ sys/dev/pccbb/pccbb_pci.c	Fri Sep 10 11:32:23 2004
@@ -287,6 +287,39 @@
 }
 
 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 0
+	device_printf(brdev, "PCI Memory allocated: 0x%08x\n", sockbase);
+#endif
+	return (0);
+}
+
+static int
 cbb_pci_attach(device_t brdev)
 {
 	static int curr_bus_number = 2; /* XXX EVILE BAD (see below) */
@@ -312,6 +345,12 @@
 	rid = CBBR_SOCKBASE;
 	sc->base_res = bus_alloc_resource_any(brdev, SYS_RES_MEMORY, &rid,
 	    RF_ACTIVE);
+	if (sc->base_res && rman_get_start(sc->base_res) < 0xa0000) {
+		bus_release_resource(brdev, SYS_RES_MEMORY, CBBR_SOCKBASE,
+		    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