Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] ipmi: add generic PCI handling

Modify the PCI hanling code for the IPMI driver to use the new method of
tables and registering, and adds more generic PCI handling for IPMI.
Unfortunately, this required a rather large rework of the way the driver
did detection so it would be more event-driven.

[bunk@stusta.de: make a struct static]
Signed-off-by: Corey Minyard <minyard@acm.org>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Corey Minyard and committed by
Linus Torvalds
b0defcdb 3c30b06d

+507 -465
+505 -464
drivers/char/ipmi/ipmi_si_intf.c
··· 52 52 #include <linux/pci.h> 53 53 #include <linux/ioport.h> 54 54 #include <linux/notifier.h> 55 + #include <linux/mutex.h> 55 56 #include <linux/kthread.h> 56 57 #include <asm/irq.h> 57 58 #ifdef CONFIG_HIGH_RES_TIMERS ··· 110 109 enum si_type { 111 110 SI_KCS, SI_SMIC, SI_BT 112 111 }; 112 + static char *si_to_str[] = { "KCS", "SMIC", "BT" }; 113 113 114 114 struct ipmi_device_id { 115 115 unsigned char device_id; ··· 149 147 int (*irq_setup)(struct smi_info *info); 150 148 void (*irq_cleanup)(struct smi_info *info); 151 149 unsigned int io_size; 150 + char *addr_source; /* ACPI, PCI, SMBIOS, hardcode, default. */ 151 + void (*addr_source_cleanup)(struct smi_info *info); 152 + void *addr_source_data; 152 153 153 154 /* Per-OEM handler, called from handle_flags(). 154 155 Returns 1 when handle_flags() needs to be re-run ··· 229 224 unsigned long incoming_messages; 230 225 231 226 struct task_struct *thread; 227 + 228 + struct list_head link; 232 229 }; 230 + 231 + static int try_smi_init(struct smi_info *smi); 233 232 234 233 static struct notifier_block *xaction_notifier_list; 235 234 static int register_xaction_notifier(struct notifier_block * nb) ··· 280 271 spin_lock(&(smi_info->msg_lock)); 281 272 282 273 /* Pick the high priority queue first. */ 283 - if (! list_empty(&(smi_info->hp_xmit_msgs))) { 274 + if (!list_empty(&(smi_info->hp_xmit_msgs))) { 284 275 entry = smi_info->hp_xmit_msgs.next; 285 - } else if (! list_empty(&(smi_info->xmit_msgs))) { 276 + } else if (!list_empty(&(smi_info->xmit_msgs))) { 286 277 entry = smi_info->xmit_msgs.next; 287 278 } 288 279 289 - if (! entry) { 280 + if (!entry) { 290 281 smi_info->curr_msg = NULL; 291 282 rv = SI_SM_IDLE; 292 283 } else { ··· 353 344 memory, we will re-enable the interrupt. */ 354 345 static inline void disable_si_irq(struct smi_info *smi_info) 355 346 { 356 - if ((smi_info->irq) && (! smi_info->interrupt_disabled)) { 347 + if ((smi_info->irq) && (!smi_info->interrupt_disabled)) { 357 348 disable_irq_nosync(smi_info->irq); 358 349 smi_info->interrupt_disabled = 1; 359 350 } ··· 384 375 } else if (smi_info->msg_flags & RECEIVE_MSG_AVAIL) { 385 376 /* Messages available. */ 386 377 smi_info->curr_msg = ipmi_alloc_smi_msg(); 387 - if (! smi_info->curr_msg) { 378 + if (!smi_info->curr_msg) { 388 379 disable_si_irq(smi_info); 389 380 smi_info->si_state = SI_NORMAL; 390 381 return; ··· 403 394 } else if (smi_info->msg_flags & EVENT_MSG_BUFFER_FULL) { 404 395 /* Events available. */ 405 396 smi_info->curr_msg = ipmi_alloc_smi_msg(); 406 - if (! smi_info->curr_msg) { 397 + if (!smi_info->curr_msg) { 407 398 disable_si_irq(smi_info); 408 399 smi_info->si_state = SI_NORMAL; 409 400 return; ··· 439 430 #endif 440 431 switch (smi_info->si_state) { 441 432 case SI_NORMAL: 442 - if (! smi_info->curr_msg) 433 + if (!smi_info->curr_msg) 443 434 break; 444 435 445 436 smi_info->curr_msg->rsp_size ··· 889 880 890 881 smi_info->last_timeout_jiffies = jiffies_now; 891 882 892 - if ((smi_info->irq) && (! smi_info->interrupt_disabled)) { 883 + if ((smi_info->irq) && (!smi_info->interrupt_disabled)) { 893 884 /* Running with interrupts, only do long timeouts. */ 894 885 smi_info->si_timer.expires = jiffies + SI_TIMEOUT_JIFFIES; 895 886 spin_lock_irqsave(&smi_info->count_lock, flags); ··· 983 974 a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS */ 984 975 985 976 #define SI_MAX_PARMS 4 986 - #define SI_MAX_DRIVERS ((SI_MAX_PARMS * 2) + 2) 987 - static struct smi_info *smi_infos[SI_MAX_DRIVERS] = 988 - { NULL, NULL, NULL, NULL }; 977 + static LIST_HEAD(smi_infos); 978 + static DECLARE_MUTEX(smi_infos_lock); 979 + static int smi_num; /* Used to sequence the SMIs */ 989 980 990 981 #define DEVICE_NAME "ipmi_si" 991 982 992 - #define DEFAULT_KCS_IO_PORT 0xca2 993 - #define DEFAULT_SMIC_IO_PORT 0xca9 994 - #define DEFAULT_BT_IO_PORT 0xe4 995 983 #define DEFAULT_REGSPACING 1 996 984 997 985 static int si_trydefaults = 1; ··· 1059 1053 " by interface number."); 1060 1054 1061 1055 1056 + #define IPMI_IO_ADDR_SPACE 0 1062 1057 #define IPMI_MEM_ADDR_SPACE 1 1063 - #define IPMI_IO_ADDR_SPACE 2 1058 + static char *addr_space_to_str[] = { "I/O", "memory" }; 1064 1059 1065 - #if defined(CONFIG_ACPI) || defined(CONFIG_DMI) || defined(CONFIG_PCI) 1066 - static int is_new_interface(int intf, u8 addr_space, unsigned long base_addr) 1060 + static void std_irq_cleanup(struct smi_info *info) 1067 1061 { 1068 - int i; 1069 - 1070 - for (i = 0; i < SI_MAX_PARMS; ++i) { 1071 - /* Don't check our address. */ 1072 - if (i == intf) 1073 - continue; 1074 - if (si_type[i] != NULL) { 1075 - if ((addr_space == IPMI_MEM_ADDR_SPACE && 1076 - base_addr == addrs[i]) || 1077 - (addr_space == IPMI_IO_ADDR_SPACE && 1078 - base_addr == ports[i])) 1079 - return 0; 1080 - } 1081 - else 1082 - break; 1083 - } 1084 - 1085 - return 1; 1062 + if (info->si_type == SI_BT) 1063 + /* Disable the interrupt in the BT interface. */ 1064 + info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, 0); 1065 + free_irq(info->irq, info); 1086 1066 } 1087 - #endif 1088 1067 1089 1068 static int std_irq_setup(struct smi_info *info) 1090 1069 { 1091 1070 int rv; 1092 1071 1093 - if (! info->irq) 1072 + if (!info->irq) 1094 1073 return 0; 1095 1074 1096 1075 if (info->si_type == SI_BT) { ··· 1084 1093 SA_INTERRUPT, 1085 1094 DEVICE_NAME, 1086 1095 info); 1087 - if (! rv) 1096 + if (!rv) 1088 1097 /* Enable the interrupt in the BT interface. */ 1089 1098 info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, 1090 1099 IPMI_BT_INTMASK_ENABLE_IRQ_BIT); ··· 1101 1110 DEVICE_NAME, info->irq); 1102 1111 info->irq = 0; 1103 1112 } else { 1113 + info->irq_cleanup = std_irq_cleanup; 1104 1114 printk(" Using irq %d\n", info->irq); 1105 1115 } 1106 1116 1107 1117 return rv; 1108 1118 } 1109 1119 1110 - static void std_irq_cleanup(struct smi_info *info) 1111 - { 1112 - if (! info->irq) 1113 - return; 1114 - 1115 - if (info->si_type == SI_BT) 1116 - /* Disable the interrupt in the BT interface. */ 1117 - info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, 0); 1118 - free_irq(info->irq, info); 1119 - } 1120 - 1121 1120 static unsigned char port_inb(struct si_sm_io *io, unsigned int offset) 1122 1121 { 1123 - unsigned int *addr = io->info; 1122 + unsigned int addr = io->addr_data; 1124 1123 1125 - return inb((*addr)+(offset*io->regspacing)); 1124 + return inb(addr + (offset * io->regspacing)); 1126 1125 } 1127 1126 1128 1127 static void port_outb(struct si_sm_io *io, unsigned int offset, 1129 1128 unsigned char b) 1130 1129 { 1131 - unsigned int *addr = io->info; 1130 + unsigned int addr = io->addr_data; 1132 1131 1133 - outb(b, (*addr)+(offset * io->regspacing)); 1132 + outb(b, addr + (offset * io->regspacing)); 1134 1133 } 1135 1134 1136 1135 static unsigned char port_inw(struct si_sm_io *io, unsigned int offset) 1137 1136 { 1138 - unsigned int *addr = io->info; 1137 + unsigned int addr = io->addr_data; 1139 1138 1140 - return (inw((*addr)+(offset * io->regspacing)) >> io->regshift) & 0xff; 1139 + return (inw(addr + (offset * io->regspacing)) >> io->regshift) & 0xff; 1141 1140 } 1142 1141 1143 1142 static void port_outw(struct si_sm_io *io, unsigned int offset, 1144 1143 unsigned char b) 1145 1144 { 1146 - unsigned int *addr = io->info; 1145 + unsigned int addr = io->addr_data; 1147 1146 1148 - outw(b << io->regshift, (*addr)+(offset * io->regspacing)); 1147 + outw(b << io->regshift, addr + (offset * io->regspacing)); 1149 1148 } 1150 1149 1151 1150 static unsigned char port_inl(struct si_sm_io *io, unsigned int offset) 1152 1151 { 1153 - unsigned int *addr = io->info; 1152 + unsigned int addr = io->addr_data; 1154 1153 1155 - return (inl((*addr)+(offset * io->regspacing)) >> io->regshift) & 0xff; 1154 + return (inl(addr + (offset * io->regspacing)) >> io->regshift) & 0xff; 1156 1155 } 1157 1156 1158 1157 static void port_outl(struct si_sm_io *io, unsigned int offset, 1159 1158 unsigned char b) 1160 1159 { 1161 - unsigned int *addr = io->info; 1160 + unsigned int addr = io->addr_data; 1162 1161 1163 - outl(b << io->regshift, (*addr)+(offset * io->regspacing)); 1162 + outl(b << io->regshift, addr+(offset * io->regspacing)); 1164 1163 } 1165 1164 1166 1165 static void port_cleanup(struct smi_info *info) 1167 1166 { 1168 - unsigned int *addr = info->io.info; 1169 - int mapsize; 1167 + unsigned int addr = info->io.addr_data; 1168 + int mapsize; 1170 1169 1171 - if (addr && (*addr)) { 1170 + if (addr) { 1172 1171 mapsize = ((info->io_size * info->io.regspacing) 1173 1172 - (info->io.regspacing - info->io.regsize)); 1174 1173 1175 - release_region (*addr, mapsize); 1174 + release_region (addr, mapsize); 1176 1175 } 1177 1176 kfree(info); 1178 1177 } 1179 1178 1180 1179 static int port_setup(struct smi_info *info) 1181 1180 { 1182 - unsigned int *addr = info->io.info; 1183 - int mapsize; 1181 + unsigned int addr = info->io.addr_data; 1182 + int mapsize; 1184 1183 1185 - if (! addr || (! *addr)) 1184 + if (!addr) 1186 1185 return -ENODEV; 1187 1186 1188 1187 info->io_cleanup = port_cleanup; ··· 1206 1225 mapsize = ((info->io_size * info->io.regspacing) 1207 1226 - (info->io.regspacing - info->io.regsize)); 1208 1227 1209 - if (request_region(*addr, mapsize, DEVICE_NAME) == NULL) 1228 + if (request_region(addr, mapsize, DEVICE_NAME) == NULL) 1210 1229 return -EIO; 1211 - return 0; 1212 - } 1213 - 1214 - static int try_init_port(int intf_num, struct smi_info **new_info) 1215 - { 1216 - struct smi_info *info; 1217 - 1218 - if (! ports[intf_num]) 1219 - return -ENODEV; 1220 - 1221 - if (! is_new_interface(intf_num, IPMI_IO_ADDR_SPACE, 1222 - ports[intf_num])) 1223 - return -ENODEV; 1224 - 1225 - info = kmalloc(sizeof(*info), GFP_KERNEL); 1226 - if (! info) { 1227 - printk(KERN_ERR "ipmi_si: Could not allocate SI data (1)\n"); 1228 - return -ENOMEM; 1229 - } 1230 - memset(info, 0, sizeof(*info)); 1231 - 1232 - info->io_setup = port_setup; 1233 - info->io.info = &(ports[intf_num]); 1234 - info->io.addr = NULL; 1235 - info->io.regspacing = regspacings[intf_num]; 1236 - if (! info->io.regspacing) 1237 - info->io.regspacing = DEFAULT_REGSPACING; 1238 - info->io.regsize = regsizes[intf_num]; 1239 - if (! info->io.regsize) 1240 - info->io.regsize = DEFAULT_REGSPACING; 1241 - info->io.regshift = regshifts[intf_num]; 1242 - info->irq = 0; 1243 - info->irq_setup = NULL; 1244 - *new_info = info; 1245 - 1246 - if (si_type[intf_num] == NULL) 1247 - si_type[intf_num] = "kcs"; 1248 - 1249 - printk("ipmi_si: Trying \"%s\" at I/O port 0x%x\n", 1250 - si_type[intf_num], ports[intf_num]); 1251 1230 return 0; 1252 1231 } 1253 1232 ··· 1262 1321 1263 1322 static void mem_cleanup(struct smi_info *info) 1264 1323 { 1265 - unsigned long *addr = info->io.info; 1324 + unsigned long addr = info->io.addr_data; 1266 1325 int mapsize; 1267 1326 1268 1327 if (info->io.addr) { ··· 1271 1330 mapsize = ((info->io_size * info->io.regspacing) 1272 1331 - (info->io.regspacing - info->io.regsize)); 1273 1332 1274 - release_mem_region(*addr, mapsize); 1333 + release_mem_region(addr, mapsize); 1275 1334 } 1276 1335 kfree(info); 1277 1336 } 1278 1337 1279 1338 static int mem_setup(struct smi_info *info) 1280 1339 { 1281 - unsigned long *addr = info->io.info; 1340 + unsigned long addr = info->io.addr_data; 1282 1341 int mapsize; 1283 1342 1284 - if (! addr || (! *addr)) 1343 + if (!addr) 1285 1344 return -ENODEV; 1286 1345 1287 1346 info->io_cleanup = mem_cleanup; ··· 1321 1380 mapsize = ((info->io_size * info->io.regspacing) 1322 1381 - (info->io.regspacing - info->io.regsize)); 1323 1382 1324 - if (request_mem_region(*addr, mapsize, DEVICE_NAME) == NULL) 1383 + if (request_mem_region(addr, mapsize, DEVICE_NAME) == NULL) 1325 1384 return -EIO; 1326 1385 1327 - info->io.addr = ioremap(*addr, mapsize); 1386 + info->io.addr = ioremap(addr, mapsize); 1328 1387 if (info->io.addr == NULL) { 1329 - release_mem_region(*addr, mapsize); 1388 + release_mem_region(addr, mapsize); 1330 1389 return -EIO; 1331 1390 } 1332 1391 return 0; 1333 1392 } 1334 1393 1335 - static int try_init_mem(int intf_num, struct smi_info **new_info) 1394 + 1395 + static __devinit void hardcode_find_bmc(void) 1336 1396 { 1397 + int i; 1337 1398 struct smi_info *info; 1338 1399 1339 - if (! addrs[intf_num]) 1340 - return -ENODEV; 1400 + for (i = 0; i < SI_MAX_PARMS; i++) { 1401 + if (!ports[i] && !addrs[i]) 1402 + continue; 1341 1403 1342 - if (! is_new_interface(intf_num, IPMI_MEM_ADDR_SPACE, 1343 - addrs[intf_num])) 1344 - return -ENODEV; 1404 + info = kzalloc(sizeof(*info), GFP_KERNEL); 1405 + if (!info) 1406 + return; 1345 1407 1346 - info = kmalloc(sizeof(*info), GFP_KERNEL); 1347 - if (! info) { 1348 - printk(KERN_ERR "ipmi_si: Could not allocate SI data (2)\n"); 1349 - return -ENOMEM; 1408 + info->addr_source = "hardcoded"; 1409 + 1410 + if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) { 1411 + info->si_type = SI_KCS; 1412 + } else if (strcmp(si_type[i], "smic") == 0) { 1413 + info->si_type = SI_SMIC; 1414 + } else if (strcmp(si_type[i], "bt") == 0) { 1415 + info->si_type = SI_BT; 1416 + } else { 1417 + printk(KERN_WARNING 1418 + "ipmi_si: Interface type specified " 1419 + "for interface %d, was invalid: %s\n", 1420 + i, si_type[i]); 1421 + kfree(info); 1422 + continue; 1423 + } 1424 + 1425 + if (ports[i]) { 1426 + /* An I/O port */ 1427 + info->io_setup = port_setup; 1428 + info->io.addr_data = ports[i]; 1429 + info->io.addr_type = IPMI_IO_ADDR_SPACE; 1430 + } else if (addrs[i]) { 1431 + /* A memory port */ 1432 + info->io_setup = mem_setup; 1433 + info->io.addr_data = addrs[i]; 1434 + info->io.addr_type = IPMI_MEM_ADDR_SPACE; 1435 + } else { 1436 + printk(KERN_WARNING 1437 + "ipmi_si: Interface type specified " 1438 + "for interface %d, " 1439 + "but port and address were not set or " 1440 + "set to zero.\n", i); 1441 + kfree(info); 1442 + continue; 1443 + } 1444 + 1445 + info->io.addr = NULL; 1446 + info->io.regspacing = regspacings[i]; 1447 + if (!info->io.regspacing) 1448 + info->io.regspacing = DEFAULT_REGSPACING; 1449 + info->io.regsize = regsizes[i]; 1450 + if (!info->io.regsize) 1451 + info->io.regsize = DEFAULT_REGSPACING; 1452 + info->io.regshift = regshifts[i]; 1453 + info->irq = irqs[i]; 1454 + if (info->irq) 1455 + info->irq_setup = std_irq_setup; 1456 + 1457 + try_smi_init(info); 1350 1458 } 1351 - memset(info, 0, sizeof(*info)); 1352 - 1353 - info->io_setup = mem_setup; 1354 - info->io.info = &addrs[intf_num]; 1355 - info->io.addr = NULL; 1356 - info->io.regspacing = regspacings[intf_num]; 1357 - if (! info->io.regspacing) 1358 - info->io.regspacing = DEFAULT_REGSPACING; 1359 - info->io.regsize = regsizes[intf_num]; 1360 - if (! info->io.regsize) 1361 - info->io.regsize = DEFAULT_REGSPACING; 1362 - info->io.regshift = regshifts[intf_num]; 1363 - info->irq = 0; 1364 - info->irq_setup = NULL; 1365 - *new_info = info; 1366 - 1367 - if (si_type[intf_num] == NULL) 1368 - si_type[intf_num] = "kcs"; 1369 - 1370 - printk("ipmi_si: Trying \"%s\" at memory address 0x%lx\n", 1371 - si_type[intf_num], addrs[intf_num]); 1372 - return 0; 1373 1459 } 1374 - 1375 1460 1376 1461 #ifdef CONFIG_ACPI 1377 1462 ··· 1437 1470 return ACPI_INTERRUPT_HANDLED; 1438 1471 } 1439 1472 1473 + static void acpi_gpe_irq_cleanup(struct smi_info *info) 1474 + { 1475 + if (!info->irq) 1476 + return; 1477 + 1478 + acpi_remove_gpe_handler(NULL, info->irq, &ipmi_acpi_gpe); 1479 + } 1480 + 1440 1481 static int acpi_gpe_irq_setup(struct smi_info *info) 1441 1482 { 1442 1483 acpi_status status; 1443 1484 1444 - if (! info->irq) 1485 + if (!info->irq) 1445 1486 return 0; 1446 1487 1447 1488 /* FIXME - is level triggered right? */ ··· 1466 1491 info->irq = 0; 1467 1492 return -EINVAL; 1468 1493 } else { 1494 + info->irq_cleanup = acpi_gpe_irq_cleanup; 1469 1495 printk(" Using ACPI GPE %d\n", info->irq); 1470 1496 return 0; 1471 1497 } 1472 - } 1473 - 1474 - static void acpi_gpe_irq_cleanup(struct smi_info *info) 1475 - { 1476 - if (! info->irq) 1477 - return; 1478 - 1479 - acpi_remove_gpe_handler(NULL, info->irq, &ipmi_acpi_gpe); 1480 1498 } 1481 1499 1482 1500 /* ··· 1514 1546 s8 spmi_id[1]; /* A '\0' terminated array starts here. */ 1515 1547 }; 1516 1548 1517 - static int try_init_acpi(int intf_num, struct smi_info **new_info) 1549 + static __devinit int try_init_acpi(struct SPMITable *spmi) 1518 1550 { 1519 1551 struct smi_info *info; 1520 - acpi_status status; 1521 - struct SPMITable *spmi; 1522 1552 char *io_type; 1523 1553 u8 addr_space; 1524 - 1525 - if (acpi_disabled) 1526 - return -ENODEV; 1527 - 1528 - if (acpi_failure) 1529 - return -ENODEV; 1530 - 1531 - status = acpi_get_firmware_table("SPMI", intf_num+1, 1532 - ACPI_LOGICAL_ADDRESSING, 1533 - (struct acpi_table_header **) &spmi); 1534 - if (status != AE_OK) { 1535 - acpi_failure = 1; 1536 - return -ENODEV; 1537 - } 1538 1554 1539 1555 if (spmi->IPMIlegacy != 1) { 1540 1556 printk(KERN_INFO "IPMI: Bad SPMI legacy %d\n", spmi->IPMIlegacy); ··· 1529 1577 addr_space = IPMI_MEM_ADDR_SPACE; 1530 1578 else 1531 1579 addr_space = IPMI_IO_ADDR_SPACE; 1532 - if (! is_new_interface(-1, addr_space, spmi->addr.address)) 1533 - return -ENODEV; 1580 + 1581 + info = kzalloc(sizeof(*info), GFP_KERNEL); 1582 + if (!info) { 1583 + printk(KERN_ERR "ipmi_si: Could not allocate SI data (3)\n"); 1584 + return -ENOMEM; 1585 + } 1586 + 1587 + info->addr_source = "ACPI"; 1534 1588 1535 1589 /* Figure out the interface type. */ 1536 1590 switch (spmi->InterfaceType) 1537 1591 { 1538 1592 case 1: /* KCS */ 1539 - si_type[intf_num] = "kcs"; 1593 + info->si_type = SI_KCS; 1540 1594 break; 1541 - 1542 1595 case 2: /* SMIC */ 1543 - si_type[intf_num] = "smic"; 1596 + info->si_type = SI_SMIC; 1544 1597 break; 1545 - 1546 1598 case 3: /* BT */ 1547 - si_type[intf_num] = "bt"; 1599 + info->si_type = SI_BT; 1548 1600 break; 1549 - 1550 1601 default: 1551 1602 printk(KERN_INFO "ipmi_si: Unknown ACPI/SPMI SI type %d\n", 1552 1603 spmi->InterfaceType); 1604 + kfree(info); 1553 1605 return -EIO; 1554 1606 } 1555 - 1556 - info = kmalloc(sizeof(*info), GFP_KERNEL); 1557 - if (! info) { 1558 - printk(KERN_ERR "ipmi_si: Could not allocate SI data (3)\n"); 1559 - return -ENOMEM; 1560 - } 1561 - memset(info, 0, sizeof(*info)); 1562 1607 1563 1608 if (spmi->InterruptType & 1) { 1564 1609 /* We've got a GPE interrupt. */ 1565 1610 info->irq = spmi->GPE; 1566 1611 info->irq_setup = acpi_gpe_irq_setup; 1567 - info->irq_cleanup = acpi_gpe_irq_cleanup; 1568 1612 } else if (spmi->InterruptType & 2) { 1569 1613 /* We've got an APIC/SAPIC interrupt. */ 1570 1614 info->irq = spmi->GlobalSystemInterrupt; 1571 1615 info->irq_setup = std_irq_setup; 1572 - info->irq_cleanup = std_irq_cleanup; 1573 1616 } else { 1574 1617 /* Use the default interrupt setting. */ 1575 1618 info->irq = 0; ··· 1573 1626 1574 1627 if (spmi->addr.register_bit_width) { 1575 1628 /* A (hopefully) properly formed register bit width. */ 1576 - regspacings[intf_num] = spmi->addr.register_bit_width / 8; 1577 1629 info->io.regspacing = spmi->addr.register_bit_width / 8; 1578 1630 } else { 1579 - regspacings[intf_num] = DEFAULT_REGSPACING; 1580 1631 info->io.regspacing = DEFAULT_REGSPACING; 1581 1632 } 1582 - regsizes[intf_num] = regspacings[intf_num]; 1583 - info->io.regsize = regsizes[intf_num]; 1584 - regshifts[intf_num] = spmi->addr.register_bit_offset; 1585 - info->io.regshift = regshifts[intf_num]; 1633 + info->io.regsize = info->io.regspacing; 1634 + info->io.regshift = spmi->addr.register_bit_offset; 1586 1635 1587 1636 if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 1588 1637 io_type = "memory"; 1589 1638 info->io_setup = mem_setup; 1590 - addrs[intf_num] = spmi->addr.address; 1591 - info->io.info = &(addrs[intf_num]); 1639 + info->io.addr_type = IPMI_IO_ADDR_SPACE; 1592 1640 } else if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) { 1593 1641 io_type = "I/O"; 1594 1642 info->io_setup = port_setup; 1595 - ports[intf_num] = spmi->addr.address; 1596 - info->io.info = &(ports[intf_num]); 1643 + info->io.addr_type = IPMI_MEM_ADDR_SPACE; 1597 1644 } else { 1598 1645 kfree(info); 1599 1646 printk("ipmi_si: Unknown ACPI I/O Address type\n"); 1600 1647 return -EIO; 1601 1648 } 1649 + info->io.addr_data = spmi->addr.address; 1602 1650 1603 - *new_info = info; 1651 + try_smi_init(info); 1604 1652 1605 - printk("ipmi_si: ACPI/SPMI specifies \"%s\" %s SI @ 0x%lx\n", 1606 - si_type[intf_num], io_type, (unsigned long) spmi->addr.address); 1607 1653 return 0; 1654 + } 1655 + 1656 + static __devinit void acpi_find_bmc(void) 1657 + { 1658 + acpi_status status; 1659 + struct SPMITable *spmi; 1660 + int i; 1661 + 1662 + if (acpi_disabled) 1663 + return; 1664 + 1665 + if (acpi_failure) 1666 + return; 1667 + 1668 + for (i = 0; ; i++) { 1669 + status = acpi_get_firmware_table("SPMI", i+1, 1670 + ACPI_LOGICAL_ADDRESSING, 1671 + (struct acpi_table_header **) 1672 + &spmi); 1673 + if (status != AE_OK) 1674 + return; 1675 + 1676 + try_init_acpi(spmi); 1677 + } 1608 1678 } 1609 1679 #endif 1610 1680 1611 1681 #ifdef CONFIG_DMI 1612 - typedef struct dmi_ipmi_data 1682 + struct dmi_ipmi_data 1613 1683 { 1614 1684 u8 type; 1615 1685 u8 addr_space; ··· 1634 1670 u8 irq; 1635 1671 u8 offset; 1636 1672 u8 slave_addr; 1637 - } dmi_ipmi_data_t; 1673 + }; 1638 1674 1639 - static dmi_ipmi_data_t dmi_data[SI_MAX_DRIVERS]; 1640 - static int dmi_data_entries; 1641 - 1642 - static int __init decode_dmi(struct dmi_header *dm, int intf_num) 1675 + static int __devinit decode_dmi(struct dmi_header *dm, 1676 + struct dmi_ipmi_data *dmi) 1643 1677 { 1644 1678 u8 *data = (u8 *)dm; 1645 1679 unsigned long base_addr; 1646 1680 u8 reg_spacing; 1647 1681 u8 len = dm->length; 1648 - dmi_ipmi_data_t *ipmi_data = dmi_data+intf_num; 1649 1682 1650 - ipmi_data->type = data[4]; 1683 + dmi->type = data[4]; 1651 1684 1652 1685 memcpy(&base_addr, data+8, sizeof(unsigned long)); 1653 1686 if (len >= 0x11) { 1654 1687 if (base_addr & 1) { 1655 1688 /* I/O */ 1656 1689 base_addr &= 0xFFFE; 1657 - ipmi_data->addr_space = IPMI_IO_ADDR_SPACE; 1690 + dmi->addr_space = IPMI_IO_ADDR_SPACE; 1658 1691 } 1659 1692 else { 1660 1693 /* Memory */ 1661 - ipmi_data->addr_space = IPMI_MEM_ADDR_SPACE; 1694 + dmi->addr_space = IPMI_MEM_ADDR_SPACE; 1662 1695 } 1663 1696 /* If bit 4 of byte 0x10 is set, then the lsb for the address 1664 1697 is odd. */ 1665 - ipmi_data->base_addr = base_addr | ((data[0x10] & 0x10) >> 4); 1698 + dmi->base_addr = base_addr | ((data[0x10] & 0x10) >> 4); 1666 1699 1667 - ipmi_data->irq = data[0x11]; 1700 + dmi->irq = data[0x11]; 1668 1701 1669 1702 /* The top two bits of byte 0x10 hold the register spacing. */ 1670 1703 reg_spacing = (data[0x10] & 0xC0) >> 6; 1671 1704 switch(reg_spacing){ 1672 1705 case 0x00: /* Byte boundaries */ 1673 - ipmi_data->offset = 1; 1706 + dmi->offset = 1; 1674 1707 break; 1675 1708 case 0x01: /* 32-bit boundaries */ 1676 - ipmi_data->offset = 4; 1709 + dmi->offset = 4; 1677 1710 break; 1678 1711 case 0x02: /* 16-byte boundaries */ 1679 - ipmi_data->offset = 16; 1712 + dmi->offset = 16; 1680 1713 break; 1681 1714 default: 1682 1715 /* Some other interface, just ignore it. */ ··· 1687 1726 * wrong (and all that I have seen are I/O) so we just 1688 1727 * ignore that bit and assume I/O. Systems that use 1689 1728 * memory should use the newer spec, anyway. */ 1690 - ipmi_data->base_addr = base_addr & 0xfffe; 1691 - ipmi_data->addr_space = IPMI_IO_ADDR_SPACE; 1692 - ipmi_data->offset = 1; 1729 + dmi->base_addr = base_addr & 0xfffe; 1730 + dmi->addr_space = IPMI_IO_ADDR_SPACE; 1731 + dmi->offset = 1; 1693 1732 } 1694 1733 1695 - ipmi_data->slave_addr = data[6]; 1734 + dmi->slave_addr = data[6]; 1696 1735 1697 - if (is_new_interface(-1, ipmi_data->addr_space,ipmi_data->base_addr)) { 1698 - dmi_data_entries++; 1699 - return 0; 1700 - } 1701 - 1702 - memset(ipmi_data, 0, sizeof(dmi_ipmi_data_t)); 1703 - 1704 - return -1; 1736 + return 0; 1705 1737 } 1706 1738 1707 - static void __init dmi_find_bmc(void) 1708 - { 1709 - struct dmi_device *dev = NULL; 1710 - int intf_num = 0; 1711 - 1712 - while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) { 1713 - if (intf_num >= SI_MAX_DRIVERS) 1714 - break; 1715 - 1716 - decode_dmi((struct dmi_header *) dev->device_data, intf_num++); 1717 - } 1718 - } 1719 - 1720 - static int try_init_smbios(int intf_num, struct smi_info **new_info) 1739 + static __devinit void try_init_dmi(struct dmi_ipmi_data *ipmi_data) 1721 1740 { 1722 1741 struct smi_info *info; 1723 - dmi_ipmi_data_t *ipmi_data = dmi_data+intf_num; 1724 - char *io_type; 1725 1742 1726 - if (intf_num >= dmi_data_entries) 1727 - return -ENODEV; 1743 + info = kzalloc(sizeof(*info), GFP_KERNEL); 1744 + if (!info) { 1745 + printk(KERN_ERR 1746 + "ipmi_si: Could not allocate SI data\n"); 1747 + return; 1748 + } 1749 + 1750 + info->addr_source = "SMBIOS"; 1728 1751 1729 1752 switch (ipmi_data->type) { 1730 - case 0x01: /* KCS */ 1731 - si_type[intf_num] = "kcs"; 1732 - break; 1733 - case 0x02: /* SMIC */ 1734 - si_type[intf_num] = "smic"; 1735 - break; 1736 - case 0x03: /* BT */ 1737 - si_type[intf_num] = "bt"; 1738 - break; 1739 - default: 1740 - return -EIO; 1753 + case 0x01: /* KCS */ 1754 + info->si_type = SI_KCS; 1755 + break; 1756 + case 0x02: /* SMIC */ 1757 + info->si_type = SI_SMIC; 1758 + break; 1759 + case 0x03: /* BT */ 1760 + info->si_type = SI_BT; 1761 + break; 1762 + default: 1763 + return; 1741 1764 } 1742 1765 1743 - info = kmalloc(sizeof(*info), GFP_KERNEL); 1744 - if (! info) { 1745 - printk(KERN_ERR "ipmi_si: Could not allocate SI data (4)\n"); 1746 - return -ENOMEM; 1747 - } 1748 - memset(info, 0, sizeof(*info)); 1749 - 1750 - if (ipmi_data->addr_space == 1) { 1751 - io_type = "memory"; 1766 + switch (ipmi_data->addr_space) { 1767 + case IPMI_MEM_ADDR_SPACE: 1752 1768 info->io_setup = mem_setup; 1753 - addrs[intf_num] = ipmi_data->base_addr; 1754 - info->io.info = &(addrs[intf_num]); 1755 - } else if (ipmi_data->addr_space == 2) { 1756 - io_type = "I/O"; 1757 - info->io_setup = port_setup; 1758 - ports[intf_num] = ipmi_data->base_addr; 1759 - info->io.info = &(ports[intf_num]); 1760 - } else { 1761 - kfree(info); 1762 - printk("ipmi_si: Unknown SMBIOS I/O Address type.\n"); 1763 - return -EIO; 1764 - } 1769 + info->io.addr_type = IPMI_MEM_ADDR_SPACE; 1770 + break; 1765 1771 1766 - regspacings[intf_num] = ipmi_data->offset; 1767 - info->io.regspacing = regspacings[intf_num]; 1768 - if (! info->io.regspacing) 1772 + case IPMI_IO_ADDR_SPACE: 1773 + info->io_setup = port_setup; 1774 + info->io.addr_type = IPMI_IO_ADDR_SPACE; 1775 + break; 1776 + 1777 + default: 1778 + kfree(info); 1779 + printk(KERN_WARNING 1780 + "ipmi_si: Unknown SMBIOS I/O Address type: %d.\n", 1781 + ipmi_data->addr_space); 1782 + return; 1783 + } 1784 + info->io.addr_data = ipmi_data->base_addr; 1785 + 1786 + info->io.regspacing = ipmi_data->offset; 1787 + if (!info->io.regspacing) 1769 1788 info->io.regspacing = DEFAULT_REGSPACING; 1770 1789 info->io.regsize = DEFAULT_REGSPACING; 1771 - info->io.regshift = regshifts[intf_num]; 1790 + info->io.regshift = 0; 1772 1791 1773 1792 info->slave_addr = ipmi_data->slave_addr; 1774 1793 1775 - irqs[intf_num] = ipmi_data->irq; 1794 + info->irq = ipmi_data->irq; 1795 + if (info->irq) 1796 + info->irq_setup = std_irq_setup; 1776 1797 1777 - *new_info = info; 1798 + try_smi_init(info); 1799 + } 1778 1800 1779 - printk("ipmi_si: Found SMBIOS-specified state machine at %s" 1780 - " address 0x%lx, slave address 0x%x\n", 1781 - io_type, (unsigned long)ipmi_data->base_addr, 1782 - ipmi_data->slave_addr); 1783 - return 0; 1801 + static void __devinit dmi_find_bmc(void) 1802 + { 1803 + struct dmi_device *dev = NULL; 1804 + struct dmi_ipmi_data data; 1805 + int rv; 1806 + 1807 + while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) { 1808 + rv = decode_dmi((struct dmi_header *) dev->device_data, &data); 1809 + if (!rv) 1810 + try_init_dmi(&data); 1811 + } 1784 1812 } 1785 1813 #endif /* CONFIG_DMI */ 1786 1814 1787 1815 #ifdef CONFIG_PCI 1788 1816 1789 - #define PCI_ERMC_CLASSCODE 0x0C0700 1817 + #define PCI_ERMC_CLASSCODE 0x0C0700 1818 + #define PCI_ERMC_CLASSCODE_MASK 0xffffff00 1819 + #define PCI_ERMC_CLASSCODE_TYPE_MASK 0xff 1820 + #define PCI_ERMC_CLASSCODE_TYPE_SMIC 0x00 1821 + #define PCI_ERMC_CLASSCODE_TYPE_KCS 0x01 1822 + #define PCI_ERMC_CLASSCODE_TYPE_BT 0x02 1823 + 1790 1824 #define PCI_HP_VENDOR_ID 0x103C 1791 1825 #define PCI_MMC_DEVICE_ID 0x121A 1792 1826 #define PCI_MMC_ADDR_CW 0x10 1793 1827 1794 - /* Avoid more than one attempt to probe pci smic. */ 1795 - static int pci_smic_checked = 0; 1796 - 1797 - static int find_pci_smic(int intf_num, struct smi_info **new_info) 1828 + static void ipmi_pci_cleanup(struct smi_info *info) 1798 1829 { 1799 - struct smi_info *info; 1800 - int error; 1801 - struct pci_dev *pci_dev = NULL; 1802 - u16 base_addr; 1803 - int fe_rmc = 0; 1830 + struct pci_dev *pdev = info->addr_source_data; 1804 1831 1805 - if (pci_smic_checked) 1806 - return -ENODEV; 1832 + pci_disable_device(pdev); 1833 + } 1807 1834 1808 - pci_smic_checked = 1; 1835 + static int __devinit ipmi_pci_probe(struct pci_dev *pdev, 1836 + const struct pci_device_id *ent) 1837 + { 1838 + int rv; 1839 + int class_type = pdev->class & PCI_ERMC_CLASSCODE_TYPE_MASK; 1840 + struct smi_info *info; 1841 + int first_reg_offset = 0; 1809 1842 1810 - pci_dev = pci_get_device(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID, NULL); 1811 - if (! pci_dev) { 1812 - pci_dev = pci_get_class(PCI_ERMC_CLASSCODE, NULL); 1813 - if (pci_dev && (pci_dev->subsystem_vendor == PCI_HP_VENDOR_ID)) 1814 - fe_rmc = 1; 1815 - else 1816 - return -ENODEV; 1843 + info = kzalloc(sizeof(*info), GFP_KERNEL); 1844 + if (!info) 1845 + return ENOMEM; 1846 + 1847 + info->addr_source = "PCI"; 1848 + 1849 + switch (class_type) { 1850 + case PCI_ERMC_CLASSCODE_TYPE_SMIC: 1851 + info->si_type = SI_SMIC; 1852 + break; 1853 + 1854 + case PCI_ERMC_CLASSCODE_TYPE_KCS: 1855 + info->si_type = SI_KCS; 1856 + break; 1857 + 1858 + case PCI_ERMC_CLASSCODE_TYPE_BT: 1859 + info->si_type = SI_BT; 1860 + break; 1861 + 1862 + default: 1863 + kfree(info); 1864 + printk(KERN_INFO "ipmi_si: %s: Unknown IPMI type: %d\n", 1865 + pci_name(pdev), class_type); 1866 + return ENOMEM; 1817 1867 } 1818 1868 1819 - error = pci_read_config_word(pci_dev, PCI_MMC_ADDR_CW, &base_addr); 1820 - if (error) 1821 - { 1822 - pci_dev_put(pci_dev); 1823 - printk(KERN_ERR 1824 - "ipmi_si: pci_read_config_word() failed (%d).\n", 1825 - error); 1826 - return -ENODEV; 1869 + rv = pci_enable_device(pdev); 1870 + if (rv) { 1871 + printk(KERN_ERR "ipmi_si: %s: couldn't enable PCI device\n", 1872 + pci_name(pdev)); 1873 + kfree(info); 1874 + return rv; 1827 1875 } 1828 1876 1829 - /* Bit 0: 1 specifies programmed I/O, 0 specifies memory mapped I/O */ 1830 - if (! (base_addr & 0x0001)) 1831 - { 1832 - pci_dev_put(pci_dev); 1833 - printk(KERN_ERR 1834 - "ipmi_si: memory mapped I/O not supported for PCI" 1835 - " smic.\n"); 1836 - return -ENODEV; 1877 + info->addr_source_cleanup = ipmi_pci_cleanup; 1878 + info->addr_source_data = pdev; 1879 + 1880 + if (pdev->subsystem_vendor == PCI_HP_VENDOR_ID) 1881 + first_reg_offset = 1; 1882 + 1883 + if (pci_resource_flags(pdev, 0) & IORESOURCE_IO) { 1884 + info->io_setup = port_setup; 1885 + info->io.addr_type = IPMI_IO_ADDR_SPACE; 1886 + } else { 1887 + info->io_setup = mem_setup; 1888 + info->io.addr_type = IPMI_MEM_ADDR_SPACE; 1837 1889 } 1890 + info->io.addr_data = pci_resource_start(pdev, 0); 1838 1891 1839 - base_addr &= 0xFFFE; 1840 - if (! fe_rmc) 1841 - /* Data register starts at base address + 1 in eRMC */ 1842 - ++base_addr; 1843 - 1844 - if (! is_new_interface(-1, IPMI_IO_ADDR_SPACE, base_addr)) { 1845 - pci_dev_put(pci_dev); 1846 - return -ENODEV; 1847 - } 1848 - 1849 - info = kmalloc(sizeof(*info), GFP_KERNEL); 1850 - if (! info) { 1851 - pci_dev_put(pci_dev); 1852 - printk(KERN_ERR "ipmi_si: Could not allocate SI data (5)\n"); 1853 - return -ENOMEM; 1854 - } 1855 - memset(info, 0, sizeof(*info)); 1856 - 1857 - info->io_setup = port_setup; 1858 - ports[intf_num] = base_addr; 1859 - info->io.info = &(ports[intf_num]); 1860 - info->io.regspacing = regspacings[intf_num]; 1861 - if (! info->io.regspacing) 1862 - info->io.regspacing = DEFAULT_REGSPACING; 1892 + info->io.regspacing = DEFAULT_REGSPACING; 1863 1893 info->io.regsize = DEFAULT_REGSPACING; 1864 - info->io.regshift = regshifts[intf_num]; 1894 + info->io.regshift = 0; 1865 1895 1866 - *new_info = info; 1896 + info->irq = pdev->irq; 1897 + if (info->irq) 1898 + info->irq_setup = std_irq_setup; 1867 1899 1868 - irqs[intf_num] = pci_dev->irq; 1869 - si_type[intf_num] = "smic"; 1900 + return try_smi_init(info); 1901 + } 1870 1902 1871 - printk("ipmi_si: Found PCI SMIC at I/O address 0x%lx\n", 1872 - (long unsigned int) base_addr); 1903 + static void __devexit ipmi_pci_remove(struct pci_dev *pdev) 1904 + { 1905 + } 1873 1906 1874 - pci_dev_put(pci_dev); 1907 + #ifdef CONFIG_PM 1908 + static int ipmi_pci_suspend(struct pci_dev *pdev, pm_message_t state) 1909 + { 1875 1910 return 0; 1876 1911 } 1877 - #endif /* CONFIG_PCI */ 1878 1912 1879 - static int try_init_plug_and_play(int intf_num, struct smi_info **new_info) 1913 + static int ipmi_pci_resume(struct pci_dev *pdev) 1880 1914 { 1881 - #ifdef CONFIG_PCI 1882 - if (find_pci_smic(intf_num, new_info) == 0) 1883 - return 0; 1884 - #endif 1885 - /* Include other methods here. */ 1886 - 1887 - return -ENODEV; 1915 + return 0; 1888 1916 } 1917 + #endif 1918 + 1919 + static struct pci_device_id ipmi_pci_devices[] = { 1920 + { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) }, 1921 + { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE) } 1922 + }; 1923 + MODULE_DEVICE_TABLE(pci, ipmi_pci_devices); 1924 + 1925 + static struct pci_driver ipmi_pci_driver = { 1926 + .name = DEVICE_NAME, 1927 + .id_table = ipmi_pci_devices, 1928 + .probe = ipmi_pci_probe, 1929 + .remove = __devexit_p(ipmi_pci_remove), 1930 + #ifdef CONFIG_PM 1931 + .suspend = ipmi_pci_suspend, 1932 + .resume = ipmi_pci_resume, 1933 + #endif 1934 + }; 1935 + #endif /* CONFIG_PCI */ 1889 1936 1890 1937 1891 1938 static int try_get_dev_id(struct smi_info *smi_info) ··· 1905 1936 int rv = 0; 1906 1937 1907 1938 resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); 1908 - if (! resp) 1939 + if (!resp) 1909 1940 return -ENOMEM; 1910 1941 1911 1942 /* Do a Get Device ID command, since it comes back with some ··· 1987 2018 struct smi_info *smi = data; 1988 2019 1989 2020 out += sprintf(out, "interrupts_enabled: %d\n", 1990 - smi->irq && ! smi->interrupt_disabled); 2021 + smi->irq && !smi->interrupt_disabled); 1991 2022 out += sprintf(out, "short_timeouts: %ld\n", 1992 2023 smi->short_timeouts); 1993 2024 out += sprintf(out, "long_timeouts: %ld\n", ··· 2063 2094 { 2064 2095 struct ipmi_device_id *id = &smi_info->device_id; 2065 2096 const char mfr[3]=DELL_IANA_MFR_ID; 2066 - if (! memcmp(mfr, id->manufacturer_id, sizeof(mfr))) { 2097 + if (!memcmp(mfr, id->manufacturer_id, sizeof(mfr))) { 2067 2098 if (id->device_id == DELL_POWEREDGE_8G_BMC_DEVICE_ID && 2068 2099 id->device_revision == DELL_POWEREDGE_8G_BMC_DEVICE_REV && 2069 2100 id->ipmi_version == DELL_POWEREDGE_8G_BMC_IPMI_VERSION) { ··· 2139 2170 { 2140 2171 struct ipmi_device_id *id = &smi_info->device_id; 2141 2172 const char mfr[3]=DELL_IANA_MFR_ID; 2142 - if (! memcmp(mfr, id->manufacturer_id, sizeof(mfr)) && 2173 + if (!memcmp(mfr, id->manufacturer_id, sizeof(mfr)) && 2143 2174 smi_info->si_type == SI_BT) 2144 2175 register_xaction_notifier(&dell_poweredge_bt_xaction_notifier); 2145 2176 } ··· 2169 2200 del_timer_sync(&smi_info->si_timer); 2170 2201 } 2171 2202 2172 - /* Returns 0 if initialized, or negative on an error. */ 2173 - static int init_one_smi(int intf_num, struct smi_info **smi) 2203 + static struct ipmi_default_vals 2174 2204 { 2175 - int rv; 2176 - struct smi_info *new_smi; 2205 + int type; 2206 + int port; 2207 + } __devinit ipmi_defaults[] = 2208 + { 2209 + { .type = SI_KCS, .port = 0xca2 }, 2210 + { .type = SI_SMIC, .port = 0xca9 }, 2211 + { .type = SI_BT, .port = 0xe4 }, 2212 + { .port = 0 } 2213 + }; 2177 2214 2215 + static __devinit void default_find_bmc(void) 2216 + { 2217 + struct smi_info *info; 2218 + int i; 2178 2219 2179 - rv = try_init_mem(intf_num, &new_smi); 2180 - if (rv) 2181 - rv = try_init_port(intf_num, &new_smi); 2182 - #ifdef CONFIG_ACPI 2183 - if (rv && si_trydefaults) 2184 - rv = try_init_acpi(intf_num, &new_smi); 2185 - #endif 2186 - #ifdef CONFIG_DMI 2187 - if (rv && si_trydefaults) 2188 - rv = try_init_smbios(intf_num, &new_smi); 2189 - #endif 2190 - if (rv && si_trydefaults) 2191 - rv = try_init_plug_and_play(intf_num, &new_smi); 2220 + for (i = 0; ; i++) { 2221 + if (!ipmi_defaults[i].port) 2222 + break; 2192 2223 2193 - if (rv) 2194 - return rv; 2224 + info = kzalloc(sizeof(*info), GFP_KERNEL); 2225 + if (!info) 2226 + return; 2227 + 2228 + info->addr_source = NULL; 2229 + 2230 + info->si_type = ipmi_defaults[i].type; 2231 + info->io_setup = port_setup; 2232 + info->io.addr_data = ipmi_defaults[i].port; 2233 + info->io.addr_type = IPMI_IO_ADDR_SPACE; 2234 + 2235 + info->io.addr = NULL; 2236 + info->io.regspacing = DEFAULT_REGSPACING; 2237 + info->io.regsize = DEFAULT_REGSPACING; 2238 + info->io.regshift = 0; 2239 + 2240 + if (try_smi_init(info) == 0) { 2241 + /* Found one... */ 2242 + printk(KERN_INFO "ipmi_si: Found default %s state" 2243 + " machine at %s address 0x%lx\n", 2244 + si_to_str[info->si_type], 2245 + addr_space_to_str[info->io.addr_type], 2246 + info->io.addr_data); 2247 + return; 2248 + } 2249 + } 2250 + } 2251 + 2252 + static int is_new_interface(struct smi_info *info) 2253 + { 2254 + struct smi_info *e; 2255 + 2256 + list_for_each_entry(e, &smi_infos, link) { 2257 + if (e->io.addr_type != info->io.addr_type) 2258 + continue; 2259 + if (e->io.addr_data == info->io.addr_data) 2260 + return 0; 2261 + } 2262 + 2263 + return 1; 2264 + } 2265 + 2266 + static int try_smi_init(struct smi_info *new_smi) 2267 + { 2268 + int rv; 2269 + 2270 + if (new_smi->addr_source) { 2271 + printk(KERN_INFO "ipmi_si: Trying %s-specified %s state" 2272 + " machine at %s address 0x%lx, slave address 0x%x," 2273 + " irq %d\n", 2274 + new_smi->addr_source, 2275 + si_to_str[new_smi->si_type], 2276 + addr_space_to_str[new_smi->io.addr_type], 2277 + new_smi->io.addr_data, 2278 + new_smi->slave_addr, new_smi->irq); 2279 + } 2280 + 2281 + down(&smi_infos_lock); 2282 + if (!is_new_interface(new_smi)) { 2283 + printk(KERN_WARNING "ipmi_si: duplicate interface\n"); 2284 + rv = -EBUSY; 2285 + goto out_err; 2286 + } 2195 2287 2196 2288 /* So we know not to free it unless we have allocated one. */ 2197 2289 new_smi->intf = NULL; 2198 2290 new_smi->si_sm = NULL; 2199 2291 new_smi->handlers = NULL; 2200 2292 2201 - if (! new_smi->irq_setup) { 2202 - new_smi->irq = irqs[intf_num]; 2203 - new_smi->irq_setup = std_irq_setup; 2204 - new_smi->irq_cleanup = std_irq_cleanup; 2205 - } 2206 - 2207 - /* Default to KCS if no type is specified. */ 2208 - if (si_type[intf_num] == NULL) { 2209 - if (si_trydefaults) 2210 - si_type[intf_num] = "kcs"; 2211 - else { 2212 - rv = -EINVAL; 2213 - goto out_err; 2214 - } 2215 - } 2216 - 2217 - /* Set up the state machine to use. */ 2218 - if (strcmp(si_type[intf_num], "kcs") == 0) { 2293 + switch (new_smi->si_type) { 2294 + case SI_KCS: 2219 2295 new_smi->handlers = &kcs_smi_handlers; 2220 - new_smi->si_type = SI_KCS; 2221 - } else if (strcmp(si_type[intf_num], "smic") == 0) { 2296 + break; 2297 + 2298 + case SI_SMIC: 2222 2299 new_smi->handlers = &smic_smi_handlers; 2223 - new_smi->si_type = SI_SMIC; 2224 - } else if (strcmp(si_type[intf_num], "bt") == 0) { 2300 + break; 2301 + 2302 + case SI_BT: 2225 2303 new_smi->handlers = &bt_smi_handlers; 2226 - new_smi->si_type = SI_BT; 2227 - } else { 2304 + break; 2305 + 2306 + default: 2228 2307 /* No support for anything else yet. */ 2229 2308 rv = -EIO; 2230 2309 goto out_err; ··· 2280 2263 2281 2264 /* Allocate the state machine's data and initialize it. */ 2282 2265 new_smi->si_sm = kmalloc(new_smi->handlers->size(), GFP_KERNEL); 2283 - if (! new_smi->si_sm) { 2266 + if (!new_smi->si_sm) { 2284 2267 printk(" Could not allocate state machine memory\n"); 2285 2268 rv = -ENOMEM; 2286 2269 goto out_err; ··· 2301 2284 2302 2285 /* Do low-level detection first. */ 2303 2286 if (new_smi->handlers->detect(new_smi->si_sm)) { 2287 + if (new_smi->addr_source) 2288 + printk(KERN_INFO "ipmi_si: Interface detection" 2289 + " failed\n"); 2304 2290 rv = -ENODEV; 2305 2291 goto out_err; 2306 2292 } 2307 2293 2308 2294 /* Attempt a get device id command. If it fails, we probably 2309 - don't have a SMI here. */ 2295 + don't have a BMC here. */ 2310 2296 rv = try_get_dev_id(new_smi); 2311 - if (rv) 2297 + if (rv) { 2298 + if (new_smi->addr_source) 2299 + printk(KERN_INFO "ipmi_si: There appears to be no BMC" 2300 + " at this location\n"); 2312 2301 goto out_err; 2302 + } 2313 2303 2314 2304 setup_oem_data_handler(new_smi); 2315 2305 setup_xaction_handlers(new_smi); 2316 2306 2317 2307 /* Try to claim any interrupts. */ 2318 - new_smi->irq_setup(new_smi); 2308 + if (new_smi->irq_setup) 2309 + new_smi->irq_setup(new_smi); 2319 2310 2320 2311 INIT_LIST_HEAD(&(new_smi->xmit_msgs)); 2321 2312 INIT_LIST_HEAD(&(new_smi->hp_xmit_msgs)); ··· 2333 2308 2334 2309 new_smi->interrupt_disabled = 0; 2335 2310 atomic_set(&new_smi->stop_operation, 0); 2336 - new_smi->intf_num = intf_num; 2311 + new_smi->intf_num = smi_num; 2312 + smi_num++; 2337 2313 2338 2314 /* Start clearing the flags before we enable interrupts or the 2339 2315 timer to avoid racing with the timer. */ ··· 2391 2365 goto out_err_stop_timer; 2392 2366 } 2393 2367 2394 - *smi = new_smi; 2368 + list_add_tail(&new_smi->link, &smi_infos); 2395 2369 2396 - printk(" IPMI %s interface initialized\n", si_type[intf_num]); 2370 + up(&smi_infos_lock); 2371 + 2372 + printk(" IPMI %s interface initialized\n",si_to_str[new_smi->si_type]); 2397 2373 2398 2374 return 0; 2399 2375 ··· 2407 2379 if (new_smi->intf) 2408 2380 ipmi_unregister_smi(new_smi->intf); 2409 2381 2410 - new_smi->irq_cleanup(new_smi); 2382 + if (new_smi->irq_cleanup) 2383 + new_smi->irq_cleanup(new_smi); 2411 2384 2412 2385 /* Wait until we know that we are out of any interrupt 2413 2386 handlers might have been running before we freed the ··· 2420 2391 new_smi->handlers->cleanup(new_smi->si_sm); 2421 2392 kfree(new_smi->si_sm); 2422 2393 } 2394 + if (new_smi->addr_source_cleanup) 2395 + new_smi->addr_source_cleanup(new_smi); 2423 2396 if (new_smi->io_cleanup) 2424 2397 new_smi->io_cleanup(new_smi); 2398 + 2399 + up(&smi_infos_lock); 2425 2400 2426 2401 return rv; 2427 2402 } 2428 2403 2429 - static __init int init_ipmi_si(void) 2404 + static __devinit int init_ipmi_si(void) 2430 2405 { 2431 - int rv = 0; 2432 - int pos = 0; 2433 2406 int i; 2434 2407 char *str; 2435 2408 ··· 2456 2425 2457 2426 printk(KERN_INFO "IPMI System Interface driver.\n"); 2458 2427 2428 + hardcode_find_bmc(); 2429 + 2459 2430 #ifdef CONFIG_DMI 2460 2431 dmi_find_bmc(); 2461 2432 #endif 2462 2433 2463 - rv = init_one_smi(0, &(smi_infos[pos])); 2464 - if (rv && ! ports[0] && si_trydefaults) { 2465 - /* If we are trying defaults and the initial port is 2466 - not set, then set it. */ 2467 - si_type[0] = "kcs"; 2468 - ports[0] = DEFAULT_KCS_IO_PORT; 2469 - rv = init_one_smi(0, &(smi_infos[pos])); 2470 - if (rv) { 2471 - /* No KCS - try SMIC */ 2472 - si_type[0] = "smic"; 2473 - ports[0] = DEFAULT_SMIC_IO_PORT; 2474 - rv = init_one_smi(0, &(smi_infos[pos])); 2475 - } 2476 - if (rv) { 2477 - /* No SMIC - try BT */ 2478 - si_type[0] = "bt"; 2479 - ports[0] = DEFAULT_BT_IO_PORT; 2480 - rv = init_one_smi(0, &(smi_infos[pos])); 2434 + #ifdef CONFIG_ACPI 2435 + if (si_trydefaults) 2436 + acpi_find_bmc(); 2437 + #endif 2438 + 2439 + #ifdef CONFIG_PCI 2440 + pci_module_init(&ipmi_pci_driver); 2441 + #endif 2442 + 2443 + if (si_trydefaults) { 2444 + down(&smi_infos_lock); 2445 + if (list_empty(&smi_infos)) { 2446 + /* No BMC was found, try defaults. */ 2447 + up(&smi_infos_lock); 2448 + default_find_bmc(); 2449 + } else { 2450 + up(&smi_infos_lock); 2481 2451 } 2482 2452 } 2483 - if (rv == 0) 2484 - pos++; 2485 2453 2486 - for (i = 1; i < SI_MAX_PARMS; i++) { 2487 - rv = init_one_smi(i, &(smi_infos[pos])); 2488 - if (rv == 0) 2489 - pos++; 2490 - } 2491 - 2492 - if (smi_infos[0] == NULL) { 2454 + down(&smi_infos_lock); 2455 + if (list_empty(&smi_infos)) { 2456 + up(&smi_infos_lock); 2457 + #ifdef CONFIG_PCI 2458 + pci_unregister_driver(&ipmi_pci_driver); 2459 + #endif 2493 2460 printk("ipmi_si: Unable to find any System Interface(s)\n"); 2494 2461 return -ENODEV; 2462 + } else { 2463 + up(&smi_infos_lock); 2464 + return 0; 2495 2465 } 2496 - 2497 - return 0; 2498 2466 } 2499 2467 module_init(init_ipmi_si); 2500 2468 2501 - static void __exit cleanup_one_si(struct smi_info *to_clean) 2469 + static void __devexit cleanup_one_si(struct smi_info *to_clean) 2502 2470 { 2503 2471 int rv; 2504 2472 unsigned long flags; 2505 2473 2506 - if (! to_clean) 2474 + if (!to_clean) 2507 2475 return; 2476 + 2477 + list_del(&to_clean->link); 2508 2478 2509 2479 /* Tell the timer and interrupt handlers that we are shutting 2510 2480 down. */ ··· 2513 2481 spin_lock(&(to_clean->msg_lock)); 2514 2482 2515 2483 atomic_inc(&to_clean->stop_operation); 2516 - to_clean->irq_cleanup(to_clean); 2484 + 2485 + if (to_clean->irq_cleanup) 2486 + to_clean->irq_cleanup(to_clean); 2517 2487 2518 2488 spin_unlock(&(to_clean->msg_lock)); 2519 2489 spin_unlock_irqrestore(&(to_clean->si_lock), flags); ··· 2545 2511 2546 2512 kfree(to_clean->si_sm); 2547 2513 2514 + if (to_clean->addr_source_cleanup) 2515 + to_clean->addr_source_cleanup(to_clean); 2548 2516 if (to_clean->io_cleanup) 2549 2517 to_clean->io_cleanup(to_clean); 2550 2518 } 2551 2519 2552 2520 static __exit void cleanup_ipmi_si(void) 2553 2521 { 2554 - int i; 2522 + struct smi_info *e, *tmp_e; 2555 2523 2556 - if (! initialized) 2524 + if (!initialized) 2557 2525 return; 2558 2526 2559 - for (i = 0; i < SI_MAX_DRIVERS; i++) { 2560 - cleanup_one_si(smi_infos[i]); 2561 - } 2527 + #ifdef CONFIG_PCI 2528 + pci_unregister_driver(&ipmi_pci_driver); 2529 + #endif 2530 + 2531 + down(&smi_infos_lock); 2532 + list_for_each_entry_safe(e, tmp_e, &smi_infos, link) 2533 + cleanup_one_si(e); 2534 + up(&smi_infos_lock); 2562 2535 } 2563 2536 module_exit(cleanup_ipmi_si); 2564 2537
+2 -1
drivers/char/ipmi/ipmi_si_sm.h
··· 50 50 51 51 /* Generic info used by the actual handling routines, the 52 52 state machine shouldn't touch these. */ 53 - void *info; 54 53 void __iomem *addr; 55 54 int regspacing; 56 55 int regsize; 57 56 int regshift; 57 + int addr_type; 58 + long addr_data; 58 59 }; 59 60 60 61 /* Results of SMI events. */