#include #include #define BITS_PER_LONG 32 #define NR_CPUS 3 #define printk(x...) printf(x) #define BITS_TO_LONGS(bits) \ (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG) #define DECLARE_BITMAP(name,bits) \ unsigned long name[BITS_TO_LONGS(bits)] #define CLEAR_BITMAP(name,bits) \ memset(name, 0, BITS_TO_LONGS(bits)*sizeof(unsigned long)) static inline void bitmap_or(volatile unsigned long *dst, const volatile unsigned long *bitmap1, const volatile unsigned long *bitmap2, int bits) { int k; for (k = 0; k < BITS_TO_LONGS(bits); ++k) dst[k] = bitmap1[k] | bitmap2[k]; } #define cpu_set(cpu, map) set_bit(cpu, (map).mask) #define cpus_or(dst,src1,src2) bitmap_or((dst).mask, (src1).mask, (src2).mask, NR_CPUS) #define cpus_coerce(map) ((map).mask[0]) #define CPU_ARRAY_SIZE BITS_TO_LONGS(NR_CPUS) #define CPU_MASK_ALL { {[0 ... CPU_ARRAY_SIZE-1] = ~0UL} } #define CPU_MASK_NONE { {[0 ... CPU_ARRAY_SIZE-1] = 0UL} } #define cpumask_of_cpu(cpu) ({ cpumask_t __cpu_mask = CPU_MASK_NONE;\ cpu_set(cpu, __cpu_mask); \ __cpu_mask; \ }) struct cpumask { unsigned long mask[CPU_ARRAY_SIZE]; }; typedef struct cpumask cpumask_t; static inline cpumask_t apicid_to_cpu_present(int phys_apicid) { return cpumask_of_cpu(phys_apicid); } int main(int argc, char **argv) { int bios_apicids[] = { 0, 3, 4, -1}, i, apicid; cpumask_t phys_cpu_present_map = CPU_MASK_NONE, tmp; for (i = 0; bios_apicids[i] != -1; i++) { apicid = bios_apicids[i]; tmp = apicid_to_cpu_present(apicid); printk("%s: tmp %lx\n", __FUNCTION__, cpus_coerce(tmp)); printk("%s: phys_cpu_present_map before %lx\n", __FUNCTION__, cpus_coerce(phys_cpu_present_map)); cpus_or(phys_cpu_present_map, phys_cpu_present_map, tmp); printk("%s: phys_cpu_present_map after %lx\n", __FUNCTION__, cpus_coerce(phys_cpu_present_map)); } return 0; }