Re: [PATCH][WAS:bcmai,axi] bcma: add Broadcom specific AMBA busdriver

From: Michael Büsch
Date: Sat May 07 2011 - 09:56:40 EST


On Sat, 2011-05-07 at 15:34 +0200, RafaÅ MiÅecki wrote:
> 2011/5/6 RafaÅ MiÅecki <zajec5@xxxxxxxxx>:
> > 2011/5/6 Arnd Bergmann <arnd@xxxxxxxx>:
> >>> +const char *bcma_device_name(u16 coreid)
> >>> +{
> >>> + switch (coreid) {
> >>> + case BCMA_CORE_OOB_ROUTER:
> >>> + return "OOB Router";
> >>> + case BCMA_CORE_INVALID:
> >>> + return "Invalid";
> >>> + case BCMA_CORE_CHIPCOMMON:
> >>> + return "ChipCommon";
> >>> + case BCMA_CORE_ILINE20:
> >>> + return "ILine 20";
> >>
> >> It's better to make that a data structure than a switch() statement,
> >> both from readability and efficiency aspects.
> >
> > Well, maybe. We call it only once, at init time. In any case we're
> > still waiting for Broadcom to clarify which cores are really used for
> > BCMA.
>
> Arnd: did you have a look at defines at all?
>
> Most of the defines have values in range 0x800 â 0x837. Converting
> this to array means loosing 0x800 u16 entries. We can not use 0x800
> offset, because there are also some defined between 0x000 and 0x800:
> #define BCMA_CORE_OOB_ROUTER 0x367 /* Out of band */
> #define BCMA_CORE_INVALID 0x700
>
> Oh and there is still:
> #define BCMA_CORE_DEFAULT 0xFFF
> we could want to include. Then we would loose additional (0xFFF -
> 0x837) u16 entries in array.
>
> I'll just leave this huge "case". As I said, it's called only once on
> initialization time. For standard PCI cards there are usually 3-5
> cores, for embedded systems this number can be bigger, but still is
> limited with 16 for 1 bus:
> #define BCMA_MAX_NR_CORES 16

The compiler does a better job than we do. I'm pretty sure that the
compiler will implement this switch statement as a series of small
lookup tables combined with some branches, if it thinks it's worth
it (also depends on flags and arch).

--
Greetings Michael.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/