From owner-freebsd-hackers@FreeBSD.ORG Sat Jul 25 13:56:37 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 08463106566B; Sat, 25 Jul 2009 13:56:37 +0000 (UTC) (envelope-from Andre.Albsmeier@siemens.com) Received: from thoth.sbs.de (thoth.sbs.de [192.35.17.2]) by mx1.freebsd.org (Postfix) with ESMTP id 8E7C28FC17; Sat, 25 Jul 2009 13:56:36 +0000 (UTC) (envelope-from Andre.Albsmeier@siemens.com) Received: from mail2.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.12.11.20060308/8.12.11) with ESMTP id n6PDuXRu004403; Sat, 25 Jul 2009 15:56:33 +0200 Received: from curry.mchp.siemens.de (curry.mchp.siemens.de [139.25.40.130]) by mail2.siemens.de (8.12.11.20060308/8.12.11) with ESMTP id n6PDuX13031726; Sat, 25 Jul 2009 15:56:33 +0200 Received: (from localhost) by curry.mchp.siemens.de (8.14.3/8.14.3) id n6PDuXqj022761; Date: Sat, 25 Jul 2009 15:56:32 +0200 From: Andre Albsmeier To: John Baldwin Message-ID: <20090725135632.GA77656@curry.mchp.siemens.de> References: <200907230835.50814.jhb@freebsd.org> <200907231425.n6NEPeRH026492@ambrisko.com> <20090723175351.GA70584@curry.mchp.siemens.de> <200907231606.11904.jhb@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200907231606.11904.jhb@freebsd.org> X-Echelon: X-Advice: Drop that crappy M$-Outlook, I'm tired of your viruses! User-Agent: Mutt/1.5.20 (2009-06-14) Cc: freebsd-hackers@freebsd.org, Andre Albsmeier Subject: SOLVED: Reading acpi memory from a driver attached to hostb X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Jul 2009 13:56:37 -0000 On Thu, 23-Jul-2009 at 16:06:11 -0400, John Baldwin wrote: > On Thursday 23 July 2009 1:53:51 pm Andre Albsmeier wrote: > > John, apparently you sent me an email (thanks a lot) which I never > > received (we have to blame our company's spam filters which I do > > not control). I'll comment on it here in my reply to Doug... > > Yes, I saw the bounces. Hopefully you see the list version of this. > > > > | Did you try > > > | doing 'bus_alloc_resource(device_get_parent(device_get_parent(dev))' in > your > > > | driver that is a child of hostb0? > > > > I tried this, well, something similar: I had to do 4 times > > device_get_parent() to end up at acpi0: > > > > mydriver -> hostb0 -> pci0 -> pcib0 -> acpi0 > > You don't actually need to do that. pci0 will pass the request up to acpi0 > eventually. You just need to ask pci0 to allocate it for you and it will see > you are not a direct child and take the 'passthrough' case here: > > struct resource * > pci_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 (device_get_parent(child) != dev) > return (BUS_ALLOC_RESOURCE(device_get_parent(dev), child, > type, rid, start, end, count, flags)); > ... > } > > Rather than trying to allocate the whole chunk of the ACPI resource, I would > just do a specific allocation like so: > > rid = 0; > res = BUS_ALLOC_RESOURCE(device_get_parent(device_get_parent(dev)), > dev, SYS_RES_MEMORY, &rid, , end address>, , RF_ACTIVE); I finally got it working. Many thanks to all, especially to Doug and John. It should have worked all the time with John's code above but due to a stupidity on my part (I specified "end" as "start + count" and not as "start + count - 1") the allocation failed. It was Doug's suggestion to disable resource allocation in acpi.c -- so the memory area was unused and I could allocate it. After entering some debugging code into acpi_resource.c and acpi.c, which do not forgive errors like the above, I found my bug ;-) No I learned a bit about acpi and found curious things like this: When using BUS_ALLOC_RESOURCE( device_get_parent(device_get_parent(dev)), ... it is pci0 appearing in acpi_alloc_resource() to allocate the resource with the parameters I specify (count == 0x4000). When using only BUS_ALLOC_RESOURCE( device_get_parent(dev), ... it is hostb0 appearing in acpi_alloc_resource() but count got changed to 0x80. However start and end remain unchanged and do not match end = start + count - 1 anymore. Thanks again, -Andre