'Determine architecture when compiling linux module

I am writing a kernel module and in it I have the following piece of code:

dma_dev->coherent_dma_mask = DMA_BIT_MASK(64);

I do not always want 64 in there: when I am targetting ARM, I want it to be

dma_dev->coherent_dma_mask = DMA_BIT_MASK(32);

So basically, for now I want:

#ifdef x86_64
    dma_dev->coherent_dma_mask = DMA_BIT_MASK(64);
#else
    dma_dev->coherent_dma_mask = DMA_BIT_MASK(32);
#endif

How can I achieve something like this?



Solution 1:[1]

There are CONFIG_ definitions for that. Something like this might fit your needs:

#if defined(CONFIG_X86_64)
    dma_dev->coherent_dma_mask = DMA_BIT_MASK(64);
#else
    dma_dev->coherent_dma_mask = DMA_BIT_MASK(32);
#endif

CONFIG_ARM (for 32bit), CONFIG_ARM64 and similar options may also come in handy.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community