From owner-freebsd-hackers Fri Dec 13 17:27:55 2002 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 7B98937B401 for ; Fri, 13 Dec 2002 17:27:54 -0800 (PST) Received: from harmony.village.org (rover.bsdimp.com [204.144.255.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id 91C4443ED8 for ; Fri, 13 Dec 2002 17:27:53 -0800 (PST) (envelope-from imp@bsdimp.com) Received: from localhost (warner@rover2.village.org [10.0.0.1]) by harmony.village.org (8.12.6/8.12.3) with ESMTP id gBE1RpuB086909; Fri, 13 Dec 2002 18:27:52 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Fri, 13 Dec 2002 18:27:41 -0700 (MST) Message-Id: <20021213.182741.39658511.imp@bsdimp.com> To: langd-freebsd-hackers@leo.org Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: more kernel programming style questions From: "M. Warner Losh" In-Reply-To: <20021213115507.GE84493@atrbg11.informatik.tu-muenchen.de> References: <20021213115507.GE84493@atrbg11.informatik.tu-muenchen.de> X-Mailer: Mew version 2.1 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG You are better off defining a series of macros that do proper bus_space_readN/bus_space_writeN for each of the fields in the register set. This will ensure that your driver works unaltered on other architectures. Directly accessing memory mapped devices is a bad idea. While it works on i386, there are some platforms that have special alignment constraints that the underlying hardware doesn't always follow. Also, the temptation to bcopy the structure does not arise (which can break, even on i386 due to how bcopy is optimized). I often have a simplified macro interface that lets me get/set any register in the device that I am using. It also makes clear that you are going to the hardware for the items, which a magic register does not. I've had to mop up a couple of drivers in the tree that did direct memory accesses that failed on some machines for mysterious reasons. Warner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message