⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linio.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
void UxCardMemOutD(ux_diva_card_t *card, void *address, dword data){	volatile dword* t = (dword*)address;	if (log_on)	{		byte *a = address;		a -= (int) card->mapped;		DPRINTF(("divas hw: wrote 0x%08x to 0x%x (memory mapped)", data, a));	}	*t = data;    return;}void UxCardMemOutBuffer(ux_diva_card_t *card, void *address, void *buffer, int length){	byte 	*pSource = buffer;	byte	*pDest = address;	while (length--)	{		*pDest++ = *pSource++;	}	if (log_on)    {		byte *a = address;		a -= (int) card->mapped;		pDest = buffer;		DPRINTF(("divas hw: wrote %02x %02x %02x %02x %02x %02x %02x %02x to 0x%x (memory mapped)", 		pDest[0] & 0xff, pDest[1] & 0xff, pDest[2] & 0xff, pDest[3] & 0xff,		pDest[4] & 0xff, pDest[5] & 0xff, pDest[6] & 0xff, pDest[7] & 0xff,		a));    }    return;}/* * Memory mapped card I/O functions */byte UxCardIoIn(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address){	byte the_byte;    outb(0xFF, card->io_base + 0xC);	outw((word) (dword) address, card->io_base + 4);	the_byte = inb(card->io_base);	if (log_on)    {		DPRINTF(("divas hw: read 0x%02x from 0x%x (I/O mapped)", 					the_byte & 0xff, address));    }    	return the_byte;}word UxCardIoInW(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address){	word the_word;	outb(0xFF, card->io_base + 0xC);	outw((word) (dword) address, card->io_base + 4);	the_word = inw(card->io_base);	if (log_on)    {		DPRINTF(("divas hw: read 0x%04x from 0x%x (I/O mapped)", 					the_word & 0xffff, address));    }	return the_word;}dword UxCardIoInD(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address){	dword the_dword;	outb(0xFF, card->io_base + 0xC);	outw((word) (dword) address, card->io_base + 4);	the_dword = inl(card->io_base);	if (log_on)    {		DPRINTF(("divas hw: read 0x%08x from 0x%x (I/O mapped)", 					the_dword, address));    }    return the_dword;}void UxCardIoInBuffer(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address, void *buffer, int length){	byte *pSource = address;	byte *pDest = buffer;	if ((word) (dword) address & 0x1)	{		outb(0xFF, card->io_base + 0xC);		outw((word) (dword) pSource, card->io_base + 4);		*pDest = (byte) inb(card->io_base);		pDest++;		pSource++;		length--;		if (!length)        {            return;        }    }	outb(0xFF, card->io_base + 0xC);	outw((word) (dword) pSource, card->io_base + 4);	insw(card->io_base, (word *)pDest,length%2 ? (length+1)>>1 : length>>1);	if (log_on)    {		pDest = buffer;		DPRINTF(("divas hw: read %02x %02x %02x %02x %02x %02x %02x %02x from 0x%x (I/O mapped)", 		pDest[0] & 0xff, pDest[1] & 0xff, pDest[2] & 0xff, pDest[3] & 0xff,		pDest[4] & 0xff, pDest[5] & 0xff, pDest[6] & 0xff, pDest[7] & 0xff,		address));    }    return;}/* Output */void UxCardIoOut(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address, byte data){	if (log_on)    {		DPRINTF(("divas hw: wrote 0x%02x to 0x%x (I/O mapped)", 					data & 0xff, address));    }	outb(0xFF, card->io_base + 0xC);	outw((word) (dword) address, card->io_base + 4);	outb((byte) data & 0xFF, card->io_base);    return;}void UxCardIoOutW(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address, word data){	if (log_on)    {		DPRINTF(("divas hw: wrote 0x%04x to 0x%x (I/O mapped)", 					data & 0xffff, address));    }	outb(0xFF, card->io_base + 0xC);	outw((word) (dword) address, card->io_base + 4);	outw((word) data & 0xFFFF, card->io_base);    return;}void UxCardIoOutD(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address, dword data){	if (log_on)    {		DPRINTF(("divas hw: wrote 0x%08x to 0x%x (I/O mapped)", data, address));    }	outb(0xFF, card->io_base + 0xC);	outw((word) (dword) address, card->io_base + 4);	outl((dword) data & 0xFFFFFFFF, card->io_base);    return;}void UxCardIoOutBuffer(ux_diva_card_t *card, void *AttachedDivasIOBase, void *address, void *buffer, int length){	byte 	*pSource = buffer;	byte	*pDest = address;	if ((word) (dword) address & 1)	{		outb(0xFF, card->io_base + 0xC);		outw((word) (dword) pDest, card->io_base + 4);		outb(*pSource, card->io_base);		pSource++;		pDest++;		length--;		if (!length)        {			return;        }	}    outb(0xFF, card->io_base + 0xC);	outw((word) (dword) pDest, card->io_base + 4);	outsw(card->io_base, (word *)pSource, length%2 ? (length+1)>>1 : length>>1);	if (log_on)    {		pDest = buffer;		DPRINTF(("divas hw: wrote %02x %02x %02x %02x %02x %02x %02x %02x to 0x%x (I/O mapped)", 		pDest[0] & 0xff, pDest[1] & 0xff, pDest[2] & 0xff, pDest[3] & 0xff,		pDest[4] & 0xff, pDest[5] & 0xff, pDest[6] & 0xff, pDest[7] & 0xff,		address));    }    return;}void 	Divasintr(int arg, void *unused, struct pt_regs *unused_regs){	int i;	card_t *card = NULL;	ux_diva_card_t *ux_ref = NULL;	for (i = 0; i < DivasCardNext; i++)	{		if (arg == DivasCards[i].cfg.irq)		{			card = &DivasCards[i];			ux_ref = card->hw;				if ((ux_ref) && (card->is_live))			{				(*ux_ref->user_isr)(ux_ref->user_isr_arg);				}			else 			{				DPRINTF(("divas: ISR couldn't locate card"));			}		}	}	return;}int UxIsrInstall(ux_diva_card_t *card, isr_fn_t *isr_fn, void *isr_arg){	int result;        card->user_isr = isr_fn;        card->user_isr_arg = isr_arg;	result = request_irq(card->irq, Divasintr, SA_INTERRUPT | SA_SHIRQ, "Divas", (void *) isr_arg);	return result;}void UxIsrRemove(ux_diva_card_t *card, void *dev_id){	free_irq(card->irq, card->user_isr_arg);}void UxPciConfigWrite(ux_diva_card_t *card, int size, int offset, void *value){	switch (size)	{	case sizeof(byte):		pcibios_write_config_byte(card->bus_num, card->func_num, offset, * (byte *) value);		break;	case sizeof(word):		pcibios_write_config_word(card->bus_num, card->func_num, offset, * (word *) value);		break;	case sizeof(dword):		pcibios_write_config_dword(card->bus_num, card->func_num, offset, * (dword *) value);		break;	default:		printk(KERN_WARNING "Divas: Invalid size in UxPciConfigWrite\n");	}}void UxPciConfigRead(ux_diva_card_t *card, int size, int offset, void *value){	switch (size)	{	case sizeof(byte):		pcibios_read_config_byte(card->bus_num, card->func_num, offset, (byte *) value);		break;	case sizeof(word):		pcibios_read_config_word(card->bus_num, card->func_num, offset, (word *) value);		break;	case sizeof(dword):		pcibios_read_config_dword(card->bus_num, card->func_num, offset, (unsigned int *) value);		break;	default:		printk(KERN_WARNING "Divas: Invalid size in UxPciConfigRead\n");	}}void *UxAlloc(unsigned int size){	void *m;	m = kmalloc(size, GFP_ATOMIC);	return m;}void UxFree(void *ptr){	kfree(ptr);}int UxCardLock(ux_diva_card_t *card){	unsigned long flags; 	//spin_lock_irqsave(&diva_lock, flags);		save_flags(flags);	cli();	return flags;	}void UxCardUnlock(ux_diva_card_t *card, int ipl){	//spin_unlock_irqrestore(&diva_lock, ipl);	restore_flags(ipl);}dword UxTimeGet(void){	return jiffies;}long UxInterlockedIncrement(ux_diva_card_t *card, long *dst){	register volatile long *p;	register long ret;	int ipl;	p =dst;		ipl = UxCardLock(card);	*p += 1;	ret = *p;	UxCardUnlock(card,ipl);	return(ret);}long UxInterlockedDecrement(ux_diva_card_t *card, long *dst){	register volatile long *p;	register long ret;	int ipl;	p =dst;		ipl = UxCardLock(card);	*p -= 1;	ret = *p;	UxCardUnlock(card,ipl);	return(ret);}

⌨️ 快捷键说明

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