📄 linio.c
字号:
/* * * Copyright (C) Eicon Technology Corporation, 2000. * * This source file is supplied for the exclusive use with Eicon * Technology Corporation's range of DIVA Server Adapters. * * Eicon File Revision : 1.16 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */#define N_DATA#include <asm/io.h>#include <asm/system.h>#include <linux/malloc.h>#include <linux/pci.h>#include <linux/delay.h>#undef N_DATA#include "uxio.h"staticint log_on=0;int Divasdevflag = 0;//spinlock_t diva_lock = SPIN_LOCK_UNLOCKED;staticux_diva_card_t card_pool[MAX_CARDS];void UxPause(long int ms){ int timeout = jiffies + ((ms * HZ) / 1000); while (time_before(jiffies, timeout));}int UxCardHandleGet(ux_diva_card_t **card, dia_card_t *cfg){ int i; ux_diva_card_t *c; if (cfg->bus_type != DIA_BUS_TYPE_PCI) { DPRINTF(("divas hw: type not PCI (%d)", cfg->bus_type)); return -1; } for (i = 0; (i < DIM(card_pool)) && (card_pool[i].in_use); i++) { ; } if (i == DIM(card_pool)) { DPRINTF(("divas hw: card_pool exhausted")); return -1; } c = *card = &card_pool[i]; switch (cfg->bus_type) { case DIA_BUS_TYPE_PCI: c->bus_num = cfg->bus_num; c->func_num = cfg->func_num; c->io_base = cfg->io_base; c->reset_base = cfg->reset_base; c->card_type = cfg->card_type; c->mapped = NULL; c->slot = cfg->slot; c->irq = (int) cfg->irq; c->pDRAM = cfg->memory[DIVAS_RAM_MEMORY]; c->pDEVICES = cfg->memory[DIVAS_REG_MEMORY]; c->pCONFIG = cfg->memory[DIVAS_CFG_MEMORY]; c->pSHARED = cfg->memory[DIVAS_SHARED_MEMORY]; c->pCONTROL = cfg->memory[DIVAS_CTL_MEMORY]; /* c->bus_type = DIA_BUS_TYPE_PCI; c->bus_num = cfg->bus_num & 0x3f; c->slot = cfg->slot; c->irq = (int) cfg->irq; c->int_priority = (int) cfg->int_priority; c->card_type = cfg->card_type; c->io_base = cfg->io_base; c->reset_base = cfg->reset_base; c->pDRAM = cfg->memory[DIVAS_RAM_MEMORY]; c->pDEVICES = cfg->memory[DIVAS_REG_MEMORY]; c->pCONFIG = cfg->memory[DIVAS_CFG_MEMORY]; c->pSHARED = cfg->memory[DIVAS_SHARED_MEMORY]; DPRINTF(("divas hw: pDRAM is 0x%x", c->pDRAM)); DPRINTF(("divas hw: pSHARED is 0x%x", c->pSHARED)); DPRINTF(("divas hw: pCONFIG is 0x%x", c->pCONFIG)); c->cm_key = cm_getbrdkey("Divas", cfg->card_id);*/ break; default: break; } c->in_use = TRUE; return 0;}void UxCardHandleFree(ux_diva_card_t *card){ card->in_use = FALSE;}#define PLX_IOBASE 0#define DIVAS_IOBASE 1void *UxCardMemAttach(ux_diva_card_t *card, int id){ if (card->card_type == DIA_CARD_TYPE_DIVA_SERVER) { switch (id) { case DIVAS_SHARED_MEMORY: card->mapped = card->pSHARED; return card->pSHARED; break; case DIVAS_RAM_MEMORY: card->mapped = card->pDRAM; return card->pDRAM; break; case DIVAS_REG_MEMORY: card->mapped = card->pDEVICES; return card->pDEVICES; break; case DIVAS_CFG_MEMORY: card->mapped = card->pCONFIG; return card->pCONFIG; break; default: ASSERT(FALSE); card->mapped = NULL; return (void *) 0; } } else if (card->card_type == DIA_CARD_TYPE_DIVA_SERVER_B) { switch (id) { case PLX_IOBASE: return (void *) card->reset_base; break; case DIVAS_IOBASE: return (void *) card->io_base; break; default: ASSERT(FALSE); return 0; } } else if (card->card_type == DIA_CARD_TYPE_DIVA_SERVER_Q) { switch (id) { case DIVAS_SHARED_MEMORY: card->mapped = card->pSHARED; return card->pSHARED; break; case DIVAS_RAM_MEMORY: card->mapped = card->pDRAM; return card->pDRAM; break; case DIVAS_REG_MEMORY: card->mapped = (void *) card->io_base; return (void *) card->io_base; break; case DIVAS_CTL_MEMORY: card->mapped = card->pCONTROL; return card->pCONTROL; break; default: // ASSERT(FALSE); DPRINTF(("divas: Trying to attach to mem %d", id)); card->mapped = NULL; return (void *) 0; } } else DPRINTF(("divas: Tried to attach to unknown card")); /* Unknown card type */ return NULL;}void UxCardMemDetach(ux_diva_card_t *card, void *address){ return; // Just a place holder. No un-mapping done.}void UxCardLog(int turn_on){ log_on = turn_on;}/* * Control Register I/O Routines to be performed on Attached I/O ports */void UxCardPortIoOut(ux_diva_card_t *card, void *AttachedBase, int offset, byte the_byte){ word base = (word) (dword) AttachedBase; base += offset; outb(the_byte, base);}void UxCardPortIoOutW(ux_diva_card_t *card, void *AttachedBase, int offset, word the_word){ word base = (word) (dword) AttachedBase; base += offset; outw(the_word, base);}void UxCardPortIoOutD(ux_diva_card_t *card, void *AttachedBase, int offset, dword the_dword){ word base = (word) (dword) AttachedBase; base += offset; outl(the_dword, base);}byte UxCardPortIoIn(ux_diva_card_t *card, void *AttachedBase, int offset){ word base = (word) (dword) AttachedBase; base += offset; return inb(base);}word UxCardPortIoInW(ux_diva_card_t *card, void *AttachedBase, int offset){ word base = (word) (dword) AttachedBase; base += offset; return inw(base);}/* * Memory mapped card I/O functions */byte UxCardMemIn(ux_diva_card_t *card, void *address){ byte b; volatile byte* t = (byte*)address; b = *t; if (log_on) { byte *a = address; a -= (int) card->mapped; DPRINTF(("divas hw: read 0x%02x from 0x%x (memory mapped)", b & 0xff, a)); } return(b); }word UxCardMemInW(ux_diva_card_t *card, void *address){ word w; volatile word* t = (word*)address; w = *t; if (log_on) { byte *a = address; a -= (int) card->mapped; DPRINTF(("divas hw: read 0x%04x from 0x%x (memory mapped)", w & 0xffff, a)); } return (w);}dword UxCardMemInD(ux_diva_card_t *card, void *address){ dword dw; volatile dword* t = (dword*)address; dw = *t; if (log_on) { byte *a = address; a -= (int) card->mapped; DPRINTF(("divas hw: read 0x%08x from 0x%x (memory mapped)", dw, a)); } return (dw);}void UxCardMemInBuffer(ux_diva_card_t *card, void *address, void *buffer, int length){ volatile byte *pSource = address; byte *pDest = buffer; while (length--) { *pDest++ = *pSource++; } if (log_on) { byte *a = address; a -= (int) card->mapped; pDest = buffer; DPRINTF(("divas hw: read %02x %02x %02x %02x %02x %02x %02x %02x from 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;}void UxCardMemOut(ux_diva_card_t *card, void *address, byte data){ volatile byte* t = (byte*)address; if (log_on) { byte *a = address; a -= (int) card->mapped; DPRINTF(("divas hw: wrote 0x%02x to 0x%x (memory mapped)", data & 0xff, a)); } *t = data; return;}void UxCardMemOutW(ux_diva_card_t *card, void *address, word data){ volatile word* t = (word*)address; if (log_on) { byte *a = address; a -= (int) card->mapped; DPRINTF(("divas hw: wrote 0x%04x to 0x%x (memory mapped)", data & 0xffff, a)); } *t = data; return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -