From owner-freebsd-hackers@FreeBSD.ORG Thu Dec 25 14:19:25 2008 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 81C5D106564A for ; Thu, 25 Dec 2008 14:19:25 +0000 (UTC) (envelope-from rpaulo@gmail.com) Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.191]) by mx1.freebsd.org (Postfix) with ESMTP id 0F5A78FC17 for ; Thu, 25 Dec 2008 14:19:24 +0000 (UTC) (envelope-from rpaulo@gmail.com) Received: by nf-out-0910.google.com with SMTP id h3so476782nfh.33 for ; Thu, 25 Dec 2008 06:19:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:cc:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:mime-version :subject:date:references:x-mailer; bh=JlMqIxFgLUiAid491k/9+Iuowv1KVJdV5lSDv/AguG4=; b=vXTQ96fP8j2lzqbQEnf0NB8zD0QpNnI2K1tUtDI9PFlLdajUh/cy8kGgOFtlHfJj5J 4btFoem5nUh35zr3tsqS5rTxungwsKFF2zKD2ZL7qwm4GxxGiZjVAxHG/7RkKsz54b0Y aM9jBD6pV4cbetoI4vJSAnPOlauRy4cmAZXGI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:cc:message-id:from:to:in-reply-to:content-type :content-transfer-encoding:mime-version:subject:date:references :x-mailer; b=Fep3eUf/WQ0dhPOT4T87bTh27CUQA+mPuADYRjO0kPIMgvKnnpGqmFhlFJdW2OdnL4 ah+FQvWZi1bAo39P0oi5xpvMRtsD/gSmB5pOPDI/nrN4eebKI/E9wrCL5+XyrNjrMBAE j0fU3CVpx8mKsr6Yt3Xbz3kj9JEt3bFRkLUdA= Received: by 10.210.92.11 with SMTP id p11mr4114486ebb.164.1230213423131; Thu, 25 Dec 2008 05:57:03 -0800 (PST) Received: from epsilon.lan ([83.144.140.27]) by mx.google.com with ESMTPS id t2sm12326150gve.19.2008.12.25.05.57.01 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 25 Dec 2008 05:57:02 -0800 (PST) Sender: Rui Paulo Message-Id: <490EB16A-F626-4A40-9716-A02A32F04ED4@freebsd.org> From: Rui Paulo To: Andre Albsmeier In-Reply-To: <20081225095333.GA12699@curry.mchp.siemens.de> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Date: Thu, 25 Dec 2008 13:57:00 +0000 References: <20081225095333.GA12699@curry.mchp.siemens.de> X-Mailer: Apple Mail (2.930.3) Cc: freebsd-hackers@freebsd.org Subject: Re: Writing device drivers: How to access a specific memory area? 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: Thu, 25 Dec 2008 14:19:25 -0000 On 25 Dec 2008, at 09:53, Andre Albsmeier wrote: > Hello all, > > I am writing a driver which needs to access memory at a > specific location. The location depends on what the BIOS > has configured into the host bridge. For example, my > current machine uses an Intel 975X chipset and the memory > location I am interested in has been set to 0xFED14000 and > is 16KB in size (this is MCHBAR of the 975X memory hub). You probably just need to do something like: rid = PCI_BAR(number); res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); And then, bus_read_4(res, offset from specified PCI BAR); > > > I have no idea how to access this space from my driver. > I have played around with bus_alloc_resource() but this > only gives me back NULL. > > However, a devinfo -r gives me: > > nexus0 > npx0 > acpi0 > Interrupt request lines: > 9 > I/O ports: > 0x10-0x1f > ... > 0x800-0x87f > I/O memory addresses: > 0x0-0x9ffff > 0xc0000-0xdffff > 0xe0000-0xfffff > 0x100000-0x7fffffff > 0xf0000000-0xf3ffffff > 0xfec00000-0xfec00fff > 0xfed13000-0xfed19fff <--- > 0xfed1c000-0xfed1ffff > 0xfed20000-0xfed3ffff > 0xfed50000-0xfed8ffff > 0xfee00000-0xfee00fff > 0xffb00000-0xffbfffff > 0xfff00000-0xffffffff > cpu0 > ... > > The line marked with <--- shows the range which includes > the location I am interested in. It is probably assigned > to the acpi0 device. > > How do I proceed from this? Do I have to hack around in > the ACPI-Code? I don't hope so ;-) You'll probably need to create a fake ACPI child driver to access it. Create your identify routine with something like: static void mydriver_identify(driver_t *driver, device_t parent) { if (device_find_child(parent, "mydriver", -1) == NULL && mydriver_match(parent)) device_add_child(parent, "mydriver", -1); } mydriver_match() should check if you were given the acpi0 device. > > > I only need access to this memory location during the > probe of my driver to read some configuration data. Is this pci configuration space ? If so, pci_read_config (man 9 pci) should be just what you need. Regards, -- Rui Paulo