From owner-freebsd-drivers@FreeBSD.ORG Sat Apr 8 00:52:00 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 1806A16A402 for ; Sat, 8 Apr 2006 00:52:00 +0000 (UTC) (envelope-from jmg@hydrogen.funkthat.com) Received: from hydrogen.funkthat.com (gate.funkthat.com [69.17.45.168]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8478F43D48 for ; Sat, 8 Apr 2006 00:51:59 +0000 (GMT) (envelope-from jmg@hydrogen.funkthat.com) Received: from hydrogen.funkthat.com (zqgfs9i3ttum38vp@localhost.funkthat.com [127.0.0.1]) by hydrogen.funkthat.com (8.13.4/8.13.3) with ESMTP id k380pwjR098257; Fri, 7 Apr 2006 17:51:58 -0700 (PDT) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.13.4/8.13.3/Submit) id k380ptPR098255; Fri, 7 Apr 2006 17:51:55 -0700 (PDT) (envelope-from jmg) Date: Fri, 7 Apr 2006 17:51:55 -0700 From: John-Mark Gurney To: David Christensen Message-ID: <20060408005155.GF72485@funkthat.com> References: <22C21BFBEB52B340A1F422CB0D88F5872E17@snoopy.randomparity.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <22C21BFBEB52B340A1F422CB0D88F5872E17@snoopy.randomparity.com> User-Agent: Mutt/1.4.2.1i X-Operating-System: FreeBSD 5.4-RELEASE-p6 i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html 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 Reply-To: John-Mark Gurney 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 00:52:00 -0000 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."