I have this code snippet from a baremetal program(here printf is for baremetal).
rd_data = *(__GICD + GICD_TYPER);
printf("--- GICD Page Status (GICD_TYPER)----------------------\n");
printf("ITLineNumber(=SPIS/32): %d\n", BIT_FIELD_READER(rd_data, 3, 0));
printf("SecurityExtn: %d\n", BIT_FIELD_READER(rd_data,10,10));
printf("MBIS: %d\n", BIT_FIELD_READER(rd_data,16,16));
printf("LPIS: %d\n", BIT_FIELD_READER(rd_data,17,17));
printf("DVIS: %d\n", BIT_FIELD_READER(rd_data,18,18));
printf("IDbits: %d\n", BIT_FIELD_READER(rd_data,23,19));
printf("A3V: %d\n", BIT_FIELD_READER(rd_data,24,24));
printf("No1N: %d\n", BIT_FIELD_READER(rd_data,25,25));
The macro BIT_FIELD_READER(rd_data, end_bit, start_bit) looks very convenient.
And now I wish to print the some registers of a peripheral registers in kernel code (using printk), and searched the kernel code if there is something similar(to copy-paste and just replace the macro).
In include/linux/bitmap.h, there is bitmap_get_value8(map, start) but it's only for getting 8 bit value.
And in include/linux/bitfield.h, I found something like #define REG_FIELD_A GENMASK(6, 0) and a = FIELD_GET(REG_FIELD_A, reg);. But this requires defining every field which is cumbsersome and not succinct. Isn't there any macro getting arbitrary bit fields using start and end position(or length) in Linux kernel code?