Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Sep 2004 11:53:47 +0200
From:      Tijl Coosemans <tijl@ulyssis.org>
To:        freebsd-mobile@freebsd.org
Subject:   Re: [PATCH] ToPIC95B cardbus on old laptop
Message-ID:  <20040910115347.03a7b2ba.tijl@ulyssis.org>
In-Reply-To: <200409090735.i897ZtuT005531@grimreaper.grondar.org>
References:  <200409040005.03105.tijl@ulyssis.org> <200409090735.i897ZtuT005531@grimreaper.grondar.org>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
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.

[-- Attachment #2 --]
--- 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);

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040910115347.03a7b2ba.tijl>