From owner-freebsd-drivers@FreeBSD.ORG Sat Apr 8 01:31:26 2006 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DDA6316A401 for ; Sat, 8 Apr 2006 01:31:26 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (vc4-2-0-87.dsl.netrack.net [199.45.160.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7AE3B43D45 for ; Sat, 8 Apr 2006 01:31:26 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from localhost (localhost.village.org [127.0.0.1] (may be forged)) by harmony.bsdimp.com (8.13.4/8.13.4) with ESMTP id k381TvGV097179; Fri, 7 Apr 2006 19:30:03 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Fri, 07 Apr 2006 19:29:56 -0600 (MDT) Message-Id: <20060407.192956.78709670.imp@bsdimp.com> To: gurney_j@resnet.uoregon.edu From: "M. Warner Losh" In-Reply-To: <20060408005155.GF72485@funkthat.com> References: <22C21BFBEB52B340A1F422CB0D88F5872E17@snoopy.randomparity.com> <20060408005155.GF72485@funkthat.com> X-Mailer: Mew version 3.3 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: freebsd-drivers@freebsd.org Subject: Re: How Do I Allocate Less Than the Entire BAR for a PCI Device? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Apr 2006 01:31:26 -0000 In message: <20060408005155.GF72485@funkthat.com> John-Mark Gurney writes: : David Christensen wrote this message on Fri, Apr 07, 2006 at 16:43 -0700: : > The Ethernet driver I'm working on has a very large PCI BAR mapping : > for memory (32MB), but I only need 128KB of that BAR memory for use : > by the driver. How can I map only the amount of memory I need with : > bus_alloc_resource()? It looks like I can specify the size if I : > also know the BAR starting address, but I'm not sure how to find that. : > Has anyone done this or know of any existing code that does this? All : > of the examples I looked at used all of BAR mapped memory. : : start and end should be relative to the resource.. so if you need to map : 128kb at 1meg of the resource, you would do: : rid = PCIR_BAR(0); /* or what ever bar the memory map is at */ : bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 1024*1024, : 1024*1024+128*1024 - 1, 128*1024, RF_ACTIVE); : : I believe this will work, I haven't tried it.. though my tracing of : the code seems to imply it might not... 0 and ~0UL should be used instead. However, I'm pretty sure that we ignore the size in the pci code. : also, most systems provide complete direct access to the pci address : space.. and on platforms like i386 w/ direct mapped pci space, even : if you want to only map 128k, the resource will still consume 32megs, : since you cannot map less than the resource lets you... (on archs like : sparc64, w/ 64bit address space, you don't have to worry about consuming : address space).. The problem is that in the phyiscal address space (on i386 at least), the BAR does take up 32MB. The card decodes that entire range, so no other cards can be in that range. : so, if you were only trying to map 128k to save kernel memory, etc, : don't bother, map the whole thing and use only the parts you need.. Agreed. Warner