From owner-freebsd-hackers@FreeBSD.ORG Tue Jul 27 12:29:53 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B887816A4CE for ; Tue, 27 Jul 2004 12:29:53 +0000 (GMT) Received: from k6.locore.ca (k6.locore.ca [205.233.216.242]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7648A43D46 for ; Tue, 27 Jul 2004 12:29:53 +0000 (GMT) (envelope-from jake@locore.ca) Received: by k6.locore.ca (Postfix, from userid 1000) id C6C15A923; Tue, 27 Jul 2004 08:29:52 -0400 (EDT) Date: Tue, 27 Jul 2004 08:29:52 -0400 From: Jake Burkholder To: Chuck Tuffli Message-ID: <20040727122952.GC18793@locore.ca> References: <20040727015923.GA63284@cre85086tuf.rose.agilent.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040727015923.GA63284@cre85086tuf.rose.agilent.com> User-Agent: Mutt/1.4.2.1i cc: hackers@freebsd.org Subject: Re: bus_alloc_resource question X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Jul 2004 12:29:53 -0000 Apparently, On Mon, Jul 26, 2004 at 06:59:24PM -0700, Chuck Tuffli said words to the effect of; > I'm having some trouble adding a bus resource and am hoping someone > can point out where I goofed. > > The host bus to a new x86 chipset has a memory mapped region in PCI > space that provides access to status and control registers. For a > driver to get access to this region, I figured it should call > bus_alloc_resource() the same as for any other memory mapped region. > This currently doesn't "just work" as the region is not a part of any > device's BARs. To add this region as a resource, I used > bus_set_resource() > > device_t dev; > uint32_t e_mem = 0xe0000000; > struct resource *ecfg_res; > > dev = pci_find_device(PCI_VENDOR_INTEL, ...); > bus_set_resource(dev, SYS_RES_MEMORY, e_mem, 0xe0000000, 0x10000000); > > but a subsequent call to bus_alloc_resource() returns NULL > > ecfg_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &e_mem, > 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE); > > A call to bus_get_resource() shows that the resource did get set as > the call returns the correct starting address and count. Is there > something else that needs to happen between the set and the alloc? Is > this even the correct approach? Thanks in advance! If this is anything like the soekris board where 0xe0000000 is just a physical address that you want to map in and read or write you can use pmap_mapdev as a quick way to do it, eg, volatile void *ptr = pmap_mapdev(0xe0000000, ...); Be warned that this, as well as bus_alloc_resource(SYS_RES_MEMORY), will allocate virtual address space for the mapping, so you should only map in exactly what you need, I imagine its just a page or 2. 0x10000000 is way too much, you will not be able to allocate that much virtual address space. Jake