int main(int argc, char *argv[]) { if (pthread_mutex_init(&sending_lock, NULL ) != 0) { printf("Fail to initialize sending_lock.\n"); exit(1); } const char *conf_file = DEFAULT_CONF_FILE; if (argc >= 3 && strcmp(argv[1], "-c") == 0) { conf_file = argv[2]; } Node *conf = read_conf_file(conf_file); if (conf == NULL ) { printf("Fail to read conf file %s\n", conf_file); exit(1); } BankConfig config = get_bank_config(conf); if (gen_pid_file(config.bank_pid_file) != 0) { printf("Fail to generate pid file.\n"); exit(1); } if (log_init(config.logging_error_log, config.logging_log_level) != 1) { printf("Fail to initialize logger.\n"); exit(1); } run_bank(config); return 0; }
/* * Detect installed memory, do some sanity checks and notify kernel about it */ static void __init probe_memory(void) { int i, j, found, cnt = 0; struct mem bank[4]; struct mem space[2] = {{SGIMC_SEG0_BADDR, 0}, {SGIMC_SEG1_BADDR, 0}}; printk(KERN_INFO "MC: Probing memory configuration:\n"); for (i = 0; i < ARRAY_SIZE(bank); i++) { unsigned int tmp = get_bank_config(i); if (!(tmp & SGIMC_MCONFIG_BVALID)) continue; bank[cnt].size = get_bank_size(tmp); bank[cnt].addr = get_bank_addr(tmp); printk(KERN_INFO " bank%d: %3ldM @ %08lx\n", i, bank[cnt].size / 1024 / 1024, bank[cnt].addr); cnt++; } /* And you thought bubble sort is dead algorithm... */ do { unsigned long addr, size; found = 0; for (i = 1; i < cnt; i++) if (bank[i-1].addr > bank[i].addr) { addr = bank[i].addr; size = bank[i].size; bank[i].addr = bank[i-1].addr; bank[i].size = bank[i-1].size; bank[i-1].addr = addr; bank[i-1].size = size; found = 1; } } while (found); /* Figure out how are memory banks mapped into spaces */ for (i = 0; i < cnt; i++) { found = 0; for (j = 0; j < ARRAY_SIZE(space) && !found; j++) if (space[j].addr + space[j].size == bank[i].addr) { space[j].size += bank[i].size; found = 1; } /* There is either hole or overlapping memory */ if (!found) printk(KERN_CRIT "MC: Memory configuration mismatch " "(%08lx), expect Bus Error soon\n", bank[i].addr); } for (i = 0; i < ARRAY_SIZE(space); i++) if (space[i].size) add_memory_region(space[i].addr, space[i].size, BOOT_MEM_RAM); }