From owner-svn-src-head@FreeBSD.ORG Wed Jun 22 16:15:16 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2B35110656F2; Wed, 22 Jun 2011 16:15:16 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 19BC78FC17; Wed, 22 Jun 2011 16:15:16 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p5MGFFR1056372; Wed, 22 Jun 2011 16:15:15 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p5MGFFLF056368; Wed, 22 Jun 2011 16:15:15 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201106221615.p5MGFFLF056368@svn.freebsd.org> From: John Baldwin Date: Wed, 22 Jun 2011 16:15:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r223424 - in head/sys: amd64/pci dev/acpica i386/pci X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jun 2011 16:15:16 -0000 Author: jhb Date: Wed Jun 22 16:15:15 2011 New Revision: 223424 URL: http://svn.freebsd.org/changeset/base/223424 Log: Add a helper routine to conditionally modify the start address of a resource allocation from an x86 Host-PCI bridge driver so that it can be reused by the ACPI Host-PCI bridge driver (and eventually the MPTable Host-PCI bridge driver) instead of duplicating the same logic. Note that this means that hw.acpi.host_mem_start is now replaced with the hw.pci.host_mem_start tunable that was already used in the non-ACPI case. This also removes hw.acpi.host_mem_start on ia64 where it was not applicable (the implementation was very x86-specific). While here, adjust the logic to apply the new start address on any "wildcard" allocation even if that allocation comes from a subset of the allowable address range. Reviewed by: imp (1) Modified: head/sys/amd64/pci/pci_bus.c head/sys/dev/acpica/acpi_pcib_acpi.c head/sys/i386/pci/pci_bus.c Modified: head/sys/amd64/pci/pci_bus.c ============================================================================== --- head/sys/amd64/pci/pci_bus.c Wed Jun 22 14:33:16 2011 (r223423) +++ head/sys/amd64/pci/pci_bus.c Wed Jun 22 16:15:15 2011 (r223424) @@ -302,35 +302,45 @@ legacy_pcib_write_ivar(device_t dev, dev return ENOENT; } +/* + * Helper routine for x86 Host-PCI bridge driver resource allocation. + * This is used to adjust the start address of wildcard allocation + * requests to avoid low addresses that are known to be problematic. + * + * If no memory preference is given, use upper 32MB slot most BIOSes + * use for their memory window. This is typically only used on older + * laptops that don't have PCI busses behind a PCI bridge, so assuming + * > 32MB is likely OK. + * + * However, this can cause problems for other chipsets, so we make + * this tunable by hw.pci.host_mem_start. + */ SYSCTL_DECL(_hw_pci); -static unsigned long legacy_host_mem_start = 0x80000000; -TUNABLE_ULONG("hw.pci.host_mem_start", &legacy_host_mem_start); -SYSCTL_ULONG(_hw_pci, OID_AUTO, host_mem_start, CTLFLAG_RDTUN, - &legacy_host_mem_start, 0x80000000, - "Limit the host bridge memory to being above this address. Must be\n\ -set at boot via a tunable."); +static unsigned long host_mem_start = 0x80000000; +TUNABLE_ULONG("hw.pci.host_mem_start", &host_mem_start); +SYSCTL_ULONG(_hw_pci, OID_AUTO, host_mem_start, CTLFLAG_RDTUN, &host_mem_start, + 0, "Limit the host bridge memory to being above this address."); + +u_long +hostb_alloc_start(int type, u_long start, u_long end, u_long count) +{ + + if (start + count - 1 != end) { + if (type == SYS_RES_MEMORY && start < host_mem_start) + start = host_mem_start; + if (type == SYS_RES_IOPORT && start < 0x1000) + start = 0x1000; + } + return (start); +} struct resource * legacy_pcib_alloc_resource(device_t dev, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { - /* - * If no memory preference is given, use upper 32MB slot most - * bioses use for their memory window. Typically other bridges - * before us get in the way to assert their preferences on memory. - * Hardcoding like this sucks, so a more MD/MI way needs to be - * found to do it. This is typically only used on older laptops - * that don't have pci busses behind pci bridge, so assuming > 32MB - * is liekly OK. - * - * However, this can cause problems for other chipsets, so we make - * this tunable by hw.pci.host_mem_start. - */ - if (type == SYS_RES_MEMORY && start == 0UL && end == ~0UL) - start = legacy_host_mem_start; - if (type == SYS_RES_IOPORT && start == 0UL && end == ~0UL) - start = 0x1000; + + start = hostb_alloc_start(type, start, end, count); return (bus_generic_alloc_resource(dev, child, type, rid, start, end, count, flags)); } Modified: head/sys/dev/acpica/acpi_pcib_acpi.c ============================================================================== --- head/sys/dev/acpica/acpi_pcib_acpi.c Wed Jun 22 14:33:16 2011 (r223423) +++ head/sys/dev/acpica/acpi_pcib_acpi.c Wed Jun 22 16:15:15 2011 (r223424) @@ -357,32 +357,14 @@ acpi_pcib_map_msi(device_t pcib, device_ return (PCIB_MAP_MSI(device_get_parent(bus), dev, irq, addr, data)); } -static u_long acpi_host_mem_start = 0x80000000; -TUNABLE_ULONG("hw.acpi.host_mem_start", &acpi_host_mem_start); - struct resource * acpi_pcib_acpi_alloc_resource(device_t dev, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { - /* - * If no memory preference is given, use upper 32MB slot most - * bioses use for their memory window. Typically other bridges - * before us get in the way to assert their preferences on memory. - * Hardcoding like this sucks, so a more MD/MI way needs to be - * found to do it. This is typically only used on older laptops - * that don't have pci busses behind pci bridge, so assuming > 32MB - * is likely OK. - * - * PCI-PCI bridges may allocate smaller ranges for their windows, - * but the heuristics here should apply to those, so we allow - * several different end addresses. - */ - if (type == SYS_RES_MEMORY && start == 0UL && (end == ~0UL || - end == 0xffffffff)) - start = acpi_host_mem_start; - if (type == SYS_RES_IOPORT && start == 0UL && (end == ~0UL || - end == 0xffff || end == 0xffffffff)) - start = 0x1000; + +#if defined(__i386__) || defined(__amd64__) + start = hostb_alloc_start(type, start, end, count); +#endif return (bus_generic_alloc_resource(dev, child, type, rid, start, end, count, flags)); } Modified: head/sys/i386/pci/pci_bus.c ============================================================================== --- head/sys/i386/pci/pci_bus.c Wed Jun 22 14:33:16 2011 (r223423) +++ head/sys/i386/pci/pci_bus.c Wed Jun 22 16:15:15 2011 (r223424) @@ -519,35 +519,45 @@ legacy_pcib_write_ivar(device_t dev, dev return ENOENT; } +/* + * Helper routine for x86 Host-PCI bridge driver resource allocation. + * This is used to adjust the start address of wildcard allocation + * requests to avoid low addresses that are known to be problematic. + * + * If no memory preference is given, use upper 32MB slot most BIOSes + * use for their memory window. This is typically only used on older + * laptops that don't have PCI busses behind a PCI bridge, so assuming + * > 32MB is likely OK. + * + * However, this can cause problems for other chipsets, so we make + * this tunable by hw.pci.host_mem_start. + */ SYSCTL_DECL(_hw_pci); -static unsigned long legacy_host_mem_start = 0x80000000; -TUNABLE_ULONG("hw.pci.host_mem_start", &legacy_host_mem_start); -SYSCTL_ULONG(_hw_pci, OID_AUTO, host_mem_start, CTLFLAG_RDTUN, - &legacy_host_mem_start, 0x80000000, - "Limit the host bridge memory to being above this address. Must be\n\ -set at boot via a tunable."); +static unsigned long host_mem_start = 0x80000000; +TUNABLE_ULONG("hw.pci.host_mem_start", &host_mem_start); +SYSCTL_ULONG(_hw_pci, OID_AUTO, host_mem_start, CTLFLAG_RDTUN, &host_mem_start, + 0, "Limit the host bridge memory to being above this address."); + +u_long +hostb_alloc_start(int type, u_long start, u_long end, u_long count) +{ + + if (start + count - 1 != end) { + if (type == SYS_RES_MEMORY && start < host_mem_start) + start = host_mem_start; + if (type == SYS_RES_IOPORT && start < 0x1000) + start = 0x1000; + } + return (start); +} struct resource * legacy_pcib_alloc_resource(device_t dev, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { - /* - * If no memory preference is given, use upper 32MB slot most - * bioses use for their memory window. Typically other bridges - * before us get in the way to assert their preferences on memory. - * Hardcoding like this sucks, so a more MD/MI way needs to be - * found to do it. This is typically only used on older laptops - * that don't have pci busses behind pci bridge, so assuming > 32MB - * is liekly OK. - * - * However, this can cause problems for other chipsets, so we make - * this tunable by hw.pci.host_mem_start. - */ - if (type == SYS_RES_MEMORY && start == 0UL && end == ~0UL) - start = legacy_host_mem_start; - if (type == SYS_RES_IOPORT && start == 0UL && end == ~0UL) - start = 0x1000; + + start = hostb_alloc_start(type, start, end, count); return (bus_generic_alloc_resource(dev, child, type, rid, start, end, count, flags)); }