From owner-freebsd-hackers@FreeBSD.ORG Mon May 25 16:07:23 2015 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D877CFBE for ; Mon, 25 May 2015 16:07:23 +0000 (UTC) (envelope-from ian@freebsd.org) Received: from pmta2.delivery6.ore.mailhop.org (pmta2.delivery6.ore.mailhop.org [54.200.129.228]) by mx1.freebsd.org (Postfix) with SMTP id B766F96B for ; Mon, 25 May 2015 16:07:23 +0000 (UTC) (envelope-from ian@freebsd.org) Received: from ilsoft.org (unknown [73.34.117.227]) by outbound2.ore.mailhop.org (Halon Mail Gateway) with ESMTPSA; Mon, 25 May 2015 16:07:37 +0000 (UTC) Received: from revolution.hippie.lan (revolution.hippie.lan [172.22.42.240]) by ilsoft.org (8.14.9/8.14.9) with ESMTP id t4PG7IP4010762; Mon, 25 May 2015 10:07:18 -0600 (MDT) (envelope-from ian@freebsd.org) Message-ID: <1432570038.1200.41.camel@freebsd.org> Subject: Re: Convert virtual address to physical address From: Ian Lepore To: Pratik Singhal Cc: freebsd-hackers Date: Mon, 25 May 2015 10:07:18 -0600 In-Reply-To: References: Content-Type: text/plain; charset="us-ascii" X-Mailer: Evolution 3.12.10 FreeBSD GNOME Team Port Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 May 2015 16:07:23 -0000 On Mon, 2015-05-25 at 19:16 +0530, Pratik Singhal wrote: > I need to convert a kernel virtual address to physical address. To do that, > as far as I know, we have 2 macros :- > > vtophys :- In sys/arm/include/pmap.h > VTOP :- In sys/boot/i386/libi386/amd64_tramp.S > > Since, I am working on arm kernel with ARM_NEW_PMAP option, I am using > vtophys macro by including the pmap.h file. > > Now, if I compile the kernel after including the pmap.h file, I am getting > the error :- > > error: field has incomplete type 'struct pmap_statistics' > struct pmap_statistics pm_stats; /* pmap statictics */ > ^ > ./machine/pmap-v6.h:127:9: note: forward declaration of 'struct > pmap_statistics' > struct pmap_statistics pm_stats; /* pmap statictics */ > > How, should I resolve this error ? Or is there some other way to convert > virtual address to physical address for arm kernel ? IMO, almost any question that begins with "I need to convert a virtual address to physical" is the wrong question to be asking. The reason you typically need physical addresses is to hand them to some piece of hardware to act on. You can't do that properly using vtophys(), you'll have cache coherency problems when the hardware touches the memory. The busdma family of functions does the right thing. If it's memory-mapped registers you're accessing rather than ram, you probably need bus_space_map() to create a proper device-memory mapping for it. -- Ian