ipmi_si_intf.c

来自「LINUX 2.6.17.4的源码」· C语言 代码 · 共 2,443 行 · 第 1/5 页

C
2,443
字号
	new_smi->intf = intf;	/* 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); 	if (new_smi->si_type != SI_BT) {		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 struct ipmi_smi_handlers handlers ={	.owner                  = THIS_MODULE,	.start_processing       = smi_start_processing,	.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 4static LIST_HEAD(smi_infos);static DEFINE_MUTEX(smi_infos_lock);static int smi_num; /* Used to sequence the SMIs */#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_IO_ADDR_SPACE  0#define IPMI_MEM_ADDR_SPACE 1static char *addr_space_to_str[] = { "I/O", "memory" };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,				 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 {		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;}static __devinit void hardcode_find_bmc(void){	int             i;	struct smi_info *info;	for (i = 0; i < SI_MAX_PARMS; i++) {		if (!ports[i] && !addrs[i])			continue;		info = kzalloc(sizeof(*info), GFP_KERNEL);		if (!info)			return;		info->addr_source = "hardcoded";		if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) {			info->si_type = SI_KCS;		} else if (strcmp(si_type[i], "smic") == 0) {			info->si_type = SI_SMIC;		} else if (strcmp(si_type[i], "bt") == 0) {			info->si_type = SI_BT;		} else {			printk(KERN_WARNING			       "ipmi_si: Interface type specified "			       "for interface %d, was invalid: %s\n",			       i, si_type[i]);			kfree(info);			continue;		}		if (ports[i]) {			/* An I/O port */			info->io_setup = port_setup;			info->io.addr_data = ports[i];			info->io.addr_type = IPMI_IO_ADDR_SPACE;		} else if (addrs[i]) {			/* A memory port */			info->io_setup = mem_setup;			info->io.addr_data = addrs[i];			info->io.addr_type = IPMI_MEM_ADDR_SPACE;		} else {			printk(KERN_WARNING			       "ipmi_si: Interface type specified "			       "for interface %d, "			       "but port and address were not set or "			       "set to zero.\n", i);			kfree(info);			continue;		}		info->io.addr = NULL;		info->io.regspacing = regspacings[i];		if (!info->io.regspacing)			info->io.regspacing = DEFAULT_REGSPACING;		info->io.regsize = regsizes[i];		if (!info->io.regsize)			info->io.regsize = DEFAULT_REGSPACING;		info->io.regshift = regshifts[i];		info->irq = irqs[i];		if (info->irq)			info->irq_setup = std_irq_setup;		try_smi_init(info);	}}#ifdef CONFIG_ACPI#include <linux/acpi.h>/* Once we get an ACPI failure, we don't try any more, because we go   through the tables sequentially.  Once we don't find a table, there   are no more. */static int acpi_failure = 0;/* For GPE-type interrupts. */static u32 ipmi_acpi_gpe(void *context){	struct smi_info *smi_info = context;	unsigned long   flags;#ifdef DEBUG_TIMING	struct timeval t;#endif	spin_lock_irqsave(&(smi_info->si_lock), flags);	spin_lock(&smi_info->count_lock);	smi_info->interrupts++;	spin_unlock(&smi_info->count_lock);	if (atomic_read(&smi_info->stop_operation))		goto out;#ifdef DEBUG_TIMING	do_gettimeofday(&t);	printk("**ACPI_GPE: %d.%9.9d\n", t.tv_sec, t.tv_usec);#endif	smi_event_handler(smi_info, 0); out:	spin_unlock_irqrestore(&(smi_info->si_lock), flags);

⌨️ 快捷键说明

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