ipmi_si_intf.c

来自「linux 内核源代码」· C语言 代码 · 共 2,489 行 · 第 1/5 页

C
2,489
字号
	struct smi_info *smi_info = data;	/* We need to clear the IRQ flag for the BT interface. */	smi_info->io.outputb(&smi_info->io, IPMI_BT_INTMASK_REG,			     IPMI_BT_INTMASK_CLEAR_IRQ_BIT			     | IPMI_BT_INTMASK_ENABLE_IRQ_BIT);	return si_irq_handler(irq, data);}static int smi_start_processing(void       *send_info,				ipmi_smi_t intf){	struct smi_info *new_smi = send_info;	int             enable = 0;	new_smi->intf = intf;	/* Try to claim any interrupts. */	if (new_smi->irq_setup)		new_smi->irq_setup(new_smi);	/* Set up the timer that drives the interface. */	setup_timer(&new_smi->si_timer, smi_timeout, (long)new_smi);	new_smi->last_timeout_jiffies = jiffies;	mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES);	/*	 * Check if the user forcefully enabled the daemon.	 */	if (new_smi->intf_num < num_force_kipmid)		enable = force_kipmid[new_smi->intf_num];	/*	 * The BT interface is efficient enough to not need a thread,	 * and there is no need for a thread if we have interrupts.	 */ 	else if ((new_smi->si_type != SI_BT) && (!new_smi->irq))		enable = 1;	if (enable) {		new_smi->thread = kthread_run(ipmi_thread, new_smi,					      "kipmi%d", new_smi->intf_num);		if (IS_ERR(new_smi->thread)) {			printk(KERN_NOTICE "ipmi_si_intf: Could not start"			       " kernel thread due to error %ld, only using"			       " timers to drive the interface\n",			       PTR_ERR(new_smi->thread));			new_smi->thread = NULL;		}	}	return 0;}static void set_maintenance_mode(void *send_info, int enable){	struct smi_info   *smi_info = send_info;	if (!enable)		atomic_set(&smi_info->req_events, 0);}static struct ipmi_smi_handlers handlers ={	.owner                  = THIS_MODULE,	.start_processing       = smi_start_processing,	.sender			= sender,	.request_events		= request_events,	.set_maintenance_mode   = set_maintenance_mode,	.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 */static LIST_HEAD(smi_infos);static DEFINE_MUTEX(smi_infos_lock);static int smi_num; /* Used to sequence the SMIs */#define DEFAULT_REGSPACING	1#define DEFAULT_REGSIZE		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 unsigned int num_addrs;static unsigned int  ports[SI_MAX_PARMS];static unsigned int num_ports;static int           irqs[SI_MAX_PARMS];static unsigned int num_irqs;static int           regspacings[SI_MAX_PARMS];static unsigned int num_regspacings;static int           regsizes[SI_MAX_PARMS];static unsigned int num_regsizes;static int           regshifts[SI_MAX_PARMS];static unsigned int num_regshifts;static int slave_addrs[SI_MAX_PARMS];static unsigned int num_slave_addrs;#define IPMI_IO_ADDR_SPACE  0#define IPMI_MEM_ADDR_SPACE 1static char *addr_space_to_str[] = { "i/o", "mem" };static int hotmod_handler(const char *val, struct kernel_param *kp);module_param_call(hotmod, hotmod_handler, NULL, NULL, 0200);MODULE_PARM_DESC(hotmod, "Add and remove interfaces.  See"		 " Documentation/IPMI.txt in the kernel sources for the"		 " gory details.");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, ulong, &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, uint, &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.");module_param_array(force_kipmid, int, &num_force_kipmid, 0);MODULE_PARM_DESC(force_kipmid, "Force the kipmi daemon to be enabled (1) or"		 " disabled(0).  Normally the IPMI driver auto-detects"		 " this, but the value may be overridden by this parm.");module_param(unload_when_empty, int, 0);MODULE_PARM_DESC(unload_when_empty, "Unload the module if no interfaces are"		 " specified or found, default is 1.  Setting to 0"		 " is useful for hot add of devices using hotmod.");static void std_irq_cleanup(struct smi_info *info){	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 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,				 IRQF_SHARED | IRQF_DISABLED,				 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,				 IRQF_SHARED | IRQF_DISABLED,				 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 {		info->irq_cleanup = std_irq_cleanup;		printk("  Using irq %d\n", info->irq);	}	return rv;}static unsigned char port_inb(struct si_sm_io *io, unsigned int offset){	unsigned int addr = io->addr_data;	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->addr_data;	outb(b, addr + (offset * io->regspacing));}static unsigned char port_inw(struct si_sm_io *io, unsigned int offset){	unsigned int addr = io->addr_data;	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->addr_data;	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->addr_data;	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->addr_data;	outl(b << io->regshift, addr+(offset * io->regspacing));}static void port_cleanup(struct smi_info *info){	unsigned int addr = info->io.addr_data;	int          idx;	if (addr) {	  	for (idx = 0; idx < info->io_size; idx++) {			release_region(addr + idx * info->io.regspacing,				       info->io.regsize);		}	}}static int port_setup(struct smi_info *info){	unsigned int addr = info->io.addr_data;	int          idx;	if (!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;	}	/* Some BIOSes reserve disjoint I/O regions in their ACPI	 * tables.  This causes problems when trying to register the	 * entire I/O region.  Therefore we must register each I/O	 * port separately.	 */  	for (idx = 0; idx < info->io_size; idx++) {		if (request_region(addr + idx * info->io.regspacing,				   info->io.regsize, DEVICE_NAME) == NULL) {			/* Undo allocations */			while (idx--) {				release_region(addr + idx * info->io.regspacing,					       info->io.regsize);			}			return -EIO;		}	}	return 0;}static unsigned char intf_mem_inb(struct si_sm_io *io, unsigned int offset){	return readb((io->addr)+(offset * io->regspacing));}static void intf_mem_outb(struct si_sm_io *io, unsigned int offset,		     unsigned char b){	writeb(b, (io->addr)+(offset * io->regspacing));}static unsigned char intf_mem_inw(struct si_sm_io *io, unsigned int offset){	return (readw((io->addr)+(offset * io->regspacing)) >> io->regshift)		& 0xff;}static void intf_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 intf_mem_inl(struct si_sm_io *io, unsigned int offset){	return (readl((io->addr)+(offset * io->regspacing)) >> io->regshift)		& 0xff;}static void intf_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.addr_data;	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);	}}static int mem_setup(struct smi_info *info){	unsigned long addr = info->io.addr_data;	int           mapsize;	if (!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 = intf_mem_inb;		info->io.outputb = intf_mem_outb;		break;	case 2:		info->io.inputb = intf_mem_inw;		info->io.outputb = intf_mem_outw;		break;	case 4:		info->io.inputb = intf_mem_inl;		info->io.outputb = intf_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;}/* * Parms come in as <op1>[:op2[:op3...]].  ops are: *   add|remove,kcs|bt|smic,mem|i/o,<address>[,<opt1>[,<opt2>[,...]]] * Options are: *   rsp=<regspacing> *   rsi=<regsize> *   rsh=<regshift> *   irq=<irq> *   ipmb=<ipmb addr> */enum hotmod_op { HM_ADD, HM_REMOVE };struct hotmod_vals {	char *name;	int  val;};static struct hotmod_vals hotmod_ops[] = {	{ "add",	HM_ADD },	{ "remove",	HM_REMOVE },	{ NULL }};static struct hotmod_vals hotmod_si[] = {	{ "kcs",	SI_KCS },	{ "smic",	SI_SMIC },	{ "bt",		SI_BT },	{ NULL }};static struct hotmod_vals hotmod_as[] = {	{ "mem",	IPMI_MEM_ADDR_SPACE },	{ "i/o",	IPMI_IO_ADDR_SPACE },	{ NULL }};static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr){	char *s;	int  i;	s = strchr(*curr, ',');	if (!s) {		printk(KERN_WARNING PFX "No hotmod %s given.\n", name);		return -EINVAL;	}	*s = '\0';	s++;	for (i = 0; hotmod_ops[i].name; i++) {		if (strcmp(*curr, v[i].name) == 0) {			*val = v[i].val;			*curr = s;			return 0;		}	}	printk(KERN_WARNING PFX "Invalid hotmod %s '%s'\n", name, *curr);	return -EINVAL;}static int check_hotmod_int_op(const char *curr, const char *option,			       const char *name, int *val)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?