[LinuxBIOS] [PATCH] Reimplementation/fixing of CS5530/CS5530A southbridge code

Uwe Hermann uwe at hermann-uwe.de
Sat Jun 16 14:46:29 CEST 2007


On Fri, Jun 15, 2007 at 02:37:56PM +0200, Peter Stuge wrote:
> >         Some even more elegant solution?
> 
> reg8 &= ~(SECONDARY_IDE_ENABLE);
> if (conf->ide1_enable)
> 	reg8 |= SECONDARY_IDE_ENABLE;
> 
> ?

Yeah, that would be another option.

As we're probably doing this type of operation quite often, I made a
macro out of it (which hopefully works for all situations):

/* If 'cond' is true this macro sets the bit(s) specified by 'bits' in the
 * 'reg' variable, otherwise it clears those bits.
 *
 * Examples:
 * reg16 = ONOFF(conf->ide0_enable, reg16, (1 << 5));
 * reg16 = ONOFF(conf->ide0_enable, reg16, (FOO | BAR));
 */
/* TODO: Move into some global header file? */

#define ONOFF(cond,reg,bits) ((cond) ? ((reg) | (bits)) : ((reg) & ~(bits)))


Usage example (from my other patch):

reg8 = pci_read_config8(dev, UDMACTL);
reg8 = ONOFF(conf->ide1_drive0_udma33_enable, reg8, SSDE0);
reg8 = ONOFF(conf->ide1_drive1_udma33_enable, reg8, SSDE1);
pci_write_config8(dev, UDMACTL, reg8);


Shall we create an include/macros.h file with some generic, useful
macros? Stuff like the above, and maybe something like:

#define MIN(a,b) ...
#define MAX(a,b) ...
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
...

This type of common macros (not too many of course) will quite likely
improve the code readability a lot.


Uwe.
-- 
http://www.hermann-uwe.de  | http://www.holsham-traders.de
http://www.crazy-hacks.org | http://www.unmaintained-free-software.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://www.coreboot.org/pipermail/coreboot/attachments/20070616/72ceb121/attachment.sig>


More information about the coreboot mailing list