Subject: Re: bus_spacing a FreeBSD driver
To: Jason Thorpe <>
From: Eduardo E. Horvath <>
List: tech-kern
Date: 09/11/1998 17:21:58
On Fri, 11 Sep 1998, Jason Thorpe wrote:

> Base and offset; you cannot use structs:
> 	(1) different arch's will have different struct padding!
> 	(2) the device may be mapped sparse by the hardware.

You should be able to get away with structures if:

You make sure you use absolute types.  Different ports have different

You place pad fields in every hole so you don't rely on the compiler
padding for you.  Always do:

	struct foo {
		int8_t bar;
		int8_t pad0;
		int16_t pad1;
		int32_t frobitz;

And never:

	struct foo {
	        int8_t bar;
	        int32_t frobitz;

You do not use bitfields (which this particular FreeBSD driver obviously

You only use the structure to dereference device registers through a
bus_space* accessor, never directly:

	bus_space_read1(tag, &foo_ptr->foo_field, ...)

Never split a register into different fields in a structure.  If it's a
16-bit register always access it through a 16-bit structure field, even if
you only want to deal with only 8-bits of that register.  Otherwise you
may have endianness problems.

Eduardo Horvath
	"I need to find a pithy new quote." -- me