Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Dec 2002 18:27:41 -0700 (MST)
From:      "M. Warner Losh" <imp@bsdimp.com>
To:        langd-freebsd-hackers@leo.org
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: more kernel programming style questions
Message-ID:  <20021213.182741.39658511.imp@bsdimp.com>
In-Reply-To: <20021213115507.GE84493@atrbg11.informatik.tu-muenchen.de>
References:  <20021213115507.GE84493@atrbg11.informatik.tu-muenchen.de>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021213.182741.39658511.imp>