Date: Fri, 7 Apr 2006 17:51:55 -0700 From: John-Mark Gurney <gurney_j@resnet.uoregon.edu> To: David Christensen <dave@randomparity.com> Cc: freebsd-drivers@freebsd.org Subject: Re: How Do I Allocate Less Than the Entire BAR for a PCI Device? Message-ID: <20060408005155.GF72485@funkthat.com> In-Reply-To: <22C21BFBEB52B340A1F422CB0D88F5872E17@snoopy.randomparity.com> References: <22C21BFBEB52B340A1F422CB0D88F5872E17@snoopy.randomparity.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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... 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).. 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.. -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060408005155.GF72485>