📄 ipmi_si_intf.c
字号:
| IPMI_BT_INTMASK_ENABLE_IRQ_BIT); return si_irq_handler(irq, data, regs);}static struct ipmi_smi_handlers handlers ={ .owner = THIS_MODULE, .sender = sender, .request_events = request_events, .set_run_to_completion = set_run_to_completion, .poll = poll,};/* There can be 4 IO ports passed in (with or without IRQs), 4 addresses, a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS */#define SI_MAX_PARMS 4#define SI_MAX_DRIVERS ((SI_MAX_PARMS * 2) + 2)static struct smi_info *smi_infos[SI_MAX_DRIVERS] ={ NULL, NULL, NULL, NULL };#define DEVICE_NAME "ipmi_si"#define DEFAULT_KCS_IO_PORT 0xca2#define DEFAULT_SMIC_IO_PORT 0xca9#define DEFAULT_BT_IO_PORT 0xe4#define DEFAULT_REGSPACING 1static int si_trydefaults = 1;static char *si_type[SI_MAX_PARMS];#define MAX_SI_TYPE_STR 30static char si_type_str[MAX_SI_TYPE_STR];static unsigned long addrs[SI_MAX_PARMS];static int num_addrs;static unsigned int ports[SI_MAX_PARMS];static int num_ports;static int irqs[SI_MAX_PARMS];static int num_irqs;static int regspacings[SI_MAX_PARMS];static int num_regspacings = 0;static int regsizes[SI_MAX_PARMS];static int num_regsizes = 0;static int regshifts[SI_MAX_PARMS];static int num_regshifts = 0;static int slave_addrs[SI_MAX_PARMS];static int num_slave_addrs = 0;module_param_named(trydefaults, si_trydefaults, bool, 0);MODULE_PARM_DESC(trydefaults, "Setting this to 'false' will disable the" " default scan of the KCS and SMIC interface at the standard" " address");module_param_string(type, si_type_str, MAX_SI_TYPE_STR, 0);MODULE_PARM_DESC(type, "Defines the type of each interface, each" " interface separated by commas. The types are 'kcs'," " 'smic', and 'bt'. For example si_type=kcs,bt will set" " the first interface to kcs and the second to bt");module_param_array(addrs, long, &num_addrs, 0);MODULE_PARM_DESC(addrs, "Sets the memory address of each interface, the" " addresses separated by commas. Only use if an interface" " is in memory. Otherwise, set it to zero or leave" " it blank.");module_param_array(ports, int, &num_ports, 0);MODULE_PARM_DESC(ports, "Sets the port address of each interface, the" " addresses separated by commas. Only use if an interface" " is a port. Otherwise, set it to zero or leave" " it blank.");module_param_array(irqs, int, &num_irqs, 0);MODULE_PARM_DESC(irqs, "Sets the interrupt of each interface, the" " addresses separated by commas. Only use if an interface" " has an interrupt. Otherwise, set it to zero or leave" " it blank.");module_param_array(regspacings, int, &num_regspacings, 0);MODULE_PARM_DESC(regspacings, "The number of bytes between the start address" " and each successive register used by the interface. For" " instance, if the start address is 0xca2 and the spacing" " is 2, then the second address is at 0xca4. Defaults" " to 1.");module_param_array(regsizes, int, &num_regsizes, 0);MODULE_PARM_DESC(regsizes, "The size of the specific IPMI register in bytes." " This should generally be 1, 2, 4, or 8 for an 8-bit," " 16-bit, 32-bit, or 64-bit register. Use this if you" " the 8-bit IPMI register has to be read from a larger" " register.");module_param_array(regshifts, int, &num_regshifts, 0);MODULE_PARM_DESC(regshifts, "The amount to shift the data read from the." " IPMI register, in bits. For instance, if the data" " is read from a 32-bit word and the IPMI data is in" " bit 8-15, then the shift would be 8");module_param_array(slave_addrs, int, &num_slave_addrs, 0);MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for" " the controller. Normally this is 0x20, but can be" " overridden by this parm. This is an array indexed" " by interface number.");#define IPMI_MEM_ADDR_SPACE 1#define IPMI_IO_ADDR_SPACE 2#if defined(CONFIG_ACPI) || defined(CONFIG_X86) || defined(CONFIG_PCI)static int is_new_interface(int intf, u8 addr_space, unsigned long base_addr){ int i; for (i = 0; i < SI_MAX_PARMS; ++i) { /* Don't check our address. */ if (i == intf) continue; if (si_type[i] != NULL) { if ((addr_space == IPMI_MEM_ADDR_SPACE && base_addr == addrs[i]) || (addr_space == IPMI_IO_ADDR_SPACE && base_addr == ports[i])) return 0; } else break; } return 1;}#endifstatic int std_irq_setup(struct smi_info *info){ int rv; if (! info->irq) return 0; if (info->si_type == SI_BT) { rv = request_irq(info->irq, si_bt_irq_handler, SA_INTERRUPT, DEVICE_NAME, info); if (! rv) /* Enable the interrupt in the BT interface. */ info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, IPMI_BT_INTMASK_ENABLE_IRQ_BIT); } else rv = request_irq(info->irq, si_irq_handler, SA_INTERRUPT, DEVICE_NAME, info); if (rv) { printk(KERN_WARNING "ipmi_si: %s unable to claim interrupt %d," " running polled\n", DEVICE_NAME, info->irq); info->irq = 0; } else { printk(" Using irq %d\n", info->irq); } return rv;}static void std_irq_cleanup(struct smi_info *info){ if (! info->irq) return; if (info->si_type == SI_BT) /* Disable the interrupt in the BT interface. */ info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, 0); free_irq(info->irq, info);}static unsigned char port_inb(struct si_sm_io *io, unsigned int offset){ unsigned int *addr = io->info; return inb((*addr)+(offset*io->regspacing));}static void port_outb(struct si_sm_io *io, unsigned int offset, unsigned char b){ unsigned int *addr = io->info; outb(b, (*addr)+(offset * io->regspacing));}static unsigned char port_inw(struct si_sm_io *io, unsigned int offset){ unsigned int *addr = io->info; return (inw((*addr)+(offset * io->regspacing)) >> io->regshift) & 0xff;}static void port_outw(struct si_sm_io *io, unsigned int offset, unsigned char b){ unsigned int *addr = io->info; outw(b << io->regshift, (*addr)+(offset * io->regspacing));}static unsigned char port_inl(struct si_sm_io *io, unsigned int offset){ unsigned int *addr = io->info; return (inl((*addr)+(offset * io->regspacing)) >> io->regshift) & 0xff;}static void port_outl(struct si_sm_io *io, unsigned int offset, unsigned char b){ unsigned int *addr = io->info; outl(b << io->regshift, (*addr)+(offset * io->regspacing));}static void port_cleanup(struct smi_info *info){ unsigned int *addr = info->io.info; int mapsize; if (addr && (*addr)) { mapsize = ((info->io_size * info->io.regspacing) - (info->io.regspacing - info->io.regsize)); release_region (*addr, mapsize); } kfree(info);}static int port_setup(struct smi_info *info){ unsigned int *addr = info->io.info; int mapsize; if (! addr || (! *addr)) return -ENODEV; info->io_cleanup = port_cleanup; /* Figure out the actual inb/inw/inl/etc routine to use based upon the register size. */ switch (info->io.regsize) { case 1: info->io.inputb = port_inb; info->io.outputb = port_outb; break; case 2: info->io.inputb = port_inw; info->io.outputb = port_outw; break; case 4: info->io.inputb = port_inl; info->io.outputb = port_outl; break; default: printk("ipmi_si: Invalid register size: %d\n", info->io.regsize); return -EINVAL; } /* Calculate the total amount of memory to claim. This is an * unusual looking calculation, but it avoids claiming any * more memory than it has to. It will claim everything * between the first address to the end of the last full * register. */ mapsize = ((info->io_size * info->io.regspacing) - (info->io.regspacing - info->io.regsize)); if (request_region(*addr, mapsize, DEVICE_NAME) == NULL) return -EIO; return 0;}static int try_init_port(int intf_num, struct smi_info **new_info){ struct smi_info *info; if (! ports[intf_num]) return -ENODEV; if (! is_new_interface(intf_num, IPMI_IO_ADDR_SPACE, ports[intf_num])) return -ENODEV; info = kmalloc(sizeof(*info), GFP_KERNEL); if (! info) { printk(KERN_ERR "ipmi_si: Could not allocate SI data (1)\n"); return -ENOMEM; } memset(info, 0, sizeof(*info)); info->io_setup = port_setup; info->io.info = &(ports[intf_num]); info->io.addr = NULL; info->io.regspacing = regspacings[intf_num]; if (! info->io.regspacing) info->io.regspacing = DEFAULT_REGSPACING; info->io.regsize = regsizes[intf_num]; if (! info->io.regsize) info->io.regsize = DEFAULT_REGSPACING; info->io.regshift = regshifts[intf_num]; info->irq = 0; info->irq_setup = NULL; *new_info = info; if (si_type[intf_num] == NULL) si_type[intf_num] = "kcs"; printk("ipmi_si: Trying \"%s\" at I/O port 0x%x\n", si_type[intf_num], ports[intf_num]); return 0;}static unsigned char mem_inb(struct si_sm_io *io, unsigned int offset){ return readb((io->addr)+(offset * io->regspacing));}static void mem_outb(struct si_sm_io *io, unsigned int offset, unsigned char b){ writeb(b, (io->addr)+(offset * io->regspacing));}static unsigned char mem_inw(struct si_sm_io *io, unsigned int offset){ return (readw((io->addr)+(offset * io->regspacing)) >> io->regshift) && 0xff;}static void mem_outw(struct si_sm_io *io, unsigned int offset, unsigned char b){ writeb(b << io->regshift, (io->addr)+(offset * io->regspacing));}static unsigned char mem_inl(struct si_sm_io *io, unsigned int offset){ return (readl((io->addr)+(offset * io->regspacing)) >> io->regshift) && 0xff;}static void mem_outl(struct si_sm_io *io, unsigned int offset, unsigned char b){ writel(b << io->regshift, (io->addr)+(offset * io->regspacing));}#ifdef readqstatic unsigned char mem_inq(struct si_sm_io *io, unsigned int offset){ return (readq((io->addr)+(offset * io->regspacing)) >> io->regshift) && 0xff;}static void mem_outq(struct si_sm_io *io, unsigned int offset, unsigned char b){ writeq(b << io->regshift, (io->addr)+(offset * io->regspacing));}#endifstatic void mem_cleanup(struct smi_info *info){ unsigned long *addr = info->io.info; int mapsize; if (info->io.addr) { iounmap(info->io.addr); mapsize = ((info->io_size * info->io.regspacing) - (info->io.regspacing - info->io.regsize)); release_mem_region(*addr, mapsize); } kfree(info);}static int mem_setup(struct smi_info *info){ unsigned long *addr = info->io.info; int mapsize; if (! addr || (! *addr)) return -ENODEV; info->io_cleanup = mem_cleanup; /* Figure out the actual readb/readw/readl/etc routine to use based upon the register size. */ switch (info->io.regsize) { case 1: info->io.inputb = mem_inb; info->io.outputb = mem_outb; break; case 2: info->io.inputb = mem_inw; info->io.outputb = mem_outw; break; case 4: info->io.inputb = mem_inl; info->io.outputb = mem_outl; break;#ifdef readq case 8: info->io.inputb = mem_inq; info->io.outputb = mem_outq; break;#endif default: printk("ipmi_si: Invalid register size: %d\n", info->io.regsize); return -EINVAL; } /* Calculate the total amount of memory to claim. This is an * unusual looking calculation, but it avoids claiming any * more memory than it has to. It will claim everything * between the first address to the end of the last full * register. */ mapsize = ((info->io_size * info->io.regspacing) - (info->io.regspacing - info->io.regsize)); if (request_mem_region(*addr, mapsize, DEVICE_NAME) == NULL) return -EIO; info->io.addr = ioremap(*addr, mapsize); if (info->io.addr == NULL) { release_mem_region(*addr, mapsize); return -EIO; } return 0;}static int try_init_mem(int intf_num, struct smi_info **new_info){ struct smi_info *info; if (! addrs[intf_num]) return -ENODEV; if (! is_new_interface(intf_num, IPMI_MEM_ADDR_SPACE, addrs[intf_num])) return -ENODEV; info = kmalloc(sizeof(*info), GFP_KERNEL); if (! info) { printk(KERN_ERR "ipmi_si: Could not allocate SI data (2)\n"); return -ENOMEM; } memset(info, 0, sizeof(*info)); info->io_setup = mem_setup; info->io.info = &addrs[intf_num]; info->io.addr = NULL; info->io.regspacing = regspacings[intf_num]; if (! info->io.regspacing) info->io.regspacing = DEFAULT_REGSPACING; info->io.regsize = regsizes[intf_num]; if (! info->io.regsize) info->io.regsize = DEFAULT_REGSPACING; info->io.regshift = regshifts[intf_num]; info->irq = 0; info->irq_setup = NULL; *new_info = info; if (si_type[intf_num] == NULL) si_type[intf_num] = "kcs"; printk("ipmi_si: Trying \"%s\" at memory address 0x%lx\n", si_type[intf_num], addrs[intf_num]); return 0;}#ifdef CONFIG_ACPI#include <linux/acpi.h>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -