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

📄 pci.c

📁 TM1300/PNX1300系列DSP(主要用于视频处理)操作系统pSOS系统的几个demo
💻 C
字号:
/*
 *  +-------------------------------------------------------------------+
 *  | Copyright (c) 1999,2000 TriMedia Technologies Inc.                |
 *  |                                                                   |
 *  | This software  is furnished under a license  and may only be used |
 *  | and copied in accordance with the terms  and conditions of such a |
 *  | license  and with  the inclusion of this  copyright notice.  This |
 *  | software or any other copies of this software may not be provided |
 *  | or otherwise  made available  to any other person.  The ownership |
 *  | and title of this software is not transferred.                    |
 *  |                                                                   |
 *  | The information  in this software  is subject  to change  without |
 *  | any  prior notice  and should not be construed as a commitment by |
 *  | TriMedia Technologies.                                            |
 *  |                                                                   |
 *  | This  code  and  information  is  provided  "as is"  without  any |
 *  | warranty of any kind,  either expressed or implied, including but |
 *  | not limited  to the implied warranties  of merchantability and/or |
 *  | fitness for any particular purpose.                               |
 *  +-------------------------------------------------------------------+
 *
 *
 *  Module name              : pci.c    1.3
 *
 *  Last update              : 14:58:07 - 00/06/19
 *
 *  Title                    : PCI access functions
 *
 *  Description              : This module provides the PCI access 
 *                             functions that are used by the ethernet
 *                             driver (dec21140.c).
 *
 *                             NOTE: this driver should use the tmPCI
 *                                   device library instead.
 *                                
 */

/*--------------------------- Includes ---------------------------------------*/

#include <tm1/mmio.h>

/*--------------------------- Functions --------------------------------------*/

void pci_write_config_dword(unsigned int bus,
			    unsigned int dn,
			    unsigned int fn,
			    unsigned int addr,
			    unsigned int val)
{
  unsigned int ret ;

  while (MMIO(BIU_STATUS) & 0x5) ;
  ret = ((bus & 0x3) |
	 ((addr & 0xfc)) |
	 ((fn & 0x3)<<8) |
	 ((0x400<<dn))) ;
  MMIO(CONFIG_ADR) = ret ;
  MMIO(CONFIG_DATA) = val ;
  MMIO(CONFIG_CTL) = 0x00 ;
  while (MMIO(BIU_STATUS) & 0x1) ;
  MMIO(BIU_STATUS) |= 0x2 ;
}

void pci_write_config_word(unsigned int bus,
			   unsigned int dn,
			   unsigned int fn,
			   unsigned int addr,
			   unsigned short val)
{
  unsigned int ret ;

  while (MMIO(BIU_STATUS) & 0x5) ;
  ret = ((bus & 0x3) |
	 ((addr & 0xfc)) |
	 ((fn & 0x3)<<8) |
	 ((0x400<<dn))) ;
  MMIO(CONFIG_ADR) = ret ;
  MMIO(CONFIG_DATA) = (val | (val << 16)) ;
  if (addr & 0x3)
    MMIO(CONFIG_CTL) = 0x03 ;
  else 
    MMIO(CONFIG_CTL) = 0x0c ;    
  while (MMIO(BIU_STATUS) & 0x1) ;
  MMIO(BIU_STATUS) |= 0x2 ;
}

void pci_write_config_byte(unsigned int bus,
			   unsigned int dn,
			   unsigned int fn,
			   unsigned int addr,
			   unsigned char val)
{
  unsigned int ret ;

  while (MMIO(BIU_STATUS) & 0x5) ;
  ret = ((bus & 0x3) |
	 ((addr & 0xfc)) |
	 ((fn & 0x3)<<8) |
	 ((0x400<<dn))) ;
  MMIO(CONFIG_ADR) = ret ;
  MMIO(CONFIG_DATA) = (val | (val << 8) | (val << 16) | (val << 24)) ;
  if (addr & 0x2)
    MMIO(CONFIG_CTL) = 0x0b ;
  else if (addr & 0x1)
    MMIO(CONFIG_CTL) = 0x0d ;
  else if (addr & 0x03)
    MMIO(CONFIG_CTL) = 0x07 ;
  else
    MMIO(CONFIG_CTL) = 0x0e ;
  while (MMIO(BIU_STATUS) & 0x1) ;
  MMIO(BIU_STATUS) |= 0x2 ;

  return ;
}


unsigned int pci_read_config_dword(unsigned int bus,
				   unsigned int dn,
				   unsigned int fn,
				   unsigned int addr)
{
  unsigned int ret ;

  while (MMIO(BIU_STATUS) & 0x5) ;
  ret = ((bus & 0x3) |
	 ((addr & 0xfc)) |
	 ((fn & 0x3)<<8) |
	 ((0x400<<dn))) ;
  MMIO(CONFIG_ADR) = ret ;
  MMIO(CONFIG_CTL) = 0x10 ;
  while (MMIO(BIU_STATUS) & 0x1) ;
  ret = MMIO(CONFIG_DATA) ;
  MMIO(BIU_STATUS) |= 0x2 ;

  return ret ;
}

unsigned short pci_read_config_word(unsigned int bus,
				    unsigned int dn,
				    unsigned int fn,
				    unsigned int addr)
{
  unsigned int ret ;

  while (MMIO(BIU_STATUS) & 0x5) ;
  ret = ((bus & 0x3) |
	 ((addr & 0xfc)) |
	 ((fn & 0x3)<<8) |
	 ((0x400<<dn))) ;
  MMIO(CONFIG_ADR) = ret ;
  if (addr & 0x2)
    MMIO(CONFIG_CTL) = 0x13 ;
  else
    MMIO(CONFIG_CTL) = 0x1c ;
  while (MMIO(BIU_STATUS) & 0x1) ;
  ret = MMIO(CONFIG_DATA) ;
  MMIO(BIU_STATUS) |= 0x2 ;

  if (addr & 0x2)
    return (ret >> 16);

  return (ret& 0xffff) ;
}

unsigned char pci_read_config_byte(unsigned int bus,
				   unsigned int dn,
				   unsigned int fn,
				   unsigned int addr)
{
  unsigned int ret ;
  int shift ;
  
  while (MMIO(BIU_STATUS) & 0x5) ;
  ret = ((bus & 0x3) |
	 ((addr & 0xfc)) |
	 ((fn & 0x3)<<8) |
	 ((0x400<<dn))) ;
  MMIO(CONFIG_ADR) = ret ;
  shift = (addr & 0x3) * 8 ;
  
  if (addr & 0x2)
    MMIO(CONFIG_CTL) = 0x1b ;
  else if (addr & 0x1)
    MMIO(CONFIG_CTL) = 0x1d ;
  else if (addr & 0x03)
    MMIO(CONFIG_CTL) = 0x17 ;
  else
    MMIO(CONFIG_CTL) = 0x1e ;
  while (MMIO(BIU_STATUS) & 0x1) ;
  ret = MMIO(CONFIG_DATA) ;
  MMIO(BIU_STATUS) |= 0x2 ;

  return ((ret>>shift) & 0xff) ;
}

#include <stdio.h>
#include <stdlib.h>

#include <ops/custom_ops.h>
#include <tm1/mmio.h>
#include "pci.h"

void ioByteWrite(unsigned long addr,
		 unsigned char val)
{
  unsigned long newVal ;

  newVal = (val) | (val << 8) | (val << 16) | (val << 24) ;
  while (MMIO(BIU_STATUS) & 0x5) ;
  MMIO(IO_ADR) = addr ;
  MMIO(IO_DATA) = newVal ;
  switch (addr & 0x3) {
  case 0:
    MMIO(IO_CTL) = 0x0e ;
    break ;
  case 1:
    MMIO(IO_CTL) = 0x0d ;
    break ;
  case 2:
    MMIO(IO_CTL) = 0x0b ;
    break ;
  case 3:
    MMIO(IO_CTL) = 0x07 ;
    break ;
  }

  
  while (MMIO(BIU_STATUS) & 0x4) ;
  MMIO(BIU_STATUS) |= 0x8 ;
}

unsigned char
ioByteRead(unsigned long addr)
{
  unsigned long newVal ;

  while (MMIO(BIU_STATUS) & 0x5) ;
  MMIO(IO_ADR) = addr;
  switch (addr & 0x3) {
  case 0:
    MMIO(IO_CTL) = 0x1e ;
    break ;
  case 1:
    MMIO(IO_CTL) = 0x1d ;
    break ;
  case 2:
    MMIO(IO_CTL) = 0x1b ;
    break ;
  case 3:
    MMIO(IO_CTL) = 0x17 ;
    break ;
  }
  while (MMIO(BIU_STATUS) & 0x4) ;
  newVal = MMIO(IO_DATA) ;
  MMIO(BIU_STATUS) |= 0x8 ;
/*  printf("newval: 0x%08x  ", newVal) ;*/
  newVal = ubytesel(newVal, (addr & 0x3)) ;
  return newVal ;
  
}

unsigned short
ioShortRead(unsigned long addr)
{
  unsigned long newVal ;
  unsigned long shift ;

  while (MMIO(BIU_STATUS) & 0x5) ;
  MMIO(IO_ADR) = addr;
  switch (addr & 0x2) {
  case 0:
    MMIO(IO_CTL) = 0x1c ;
    shift = 0 ;
    break ;
  case 2:
    MMIO(IO_CTL) = 0x13 ;
    shift = 16 ;
    break ;
  }
  while (MMIO(BIU_STATUS) & 0x4) ;
  newVal = MMIO(IO_DATA) >> shift;
  MMIO(BIU_STATUS) |= 0x8 ;
  return (newVal >> shift) & 0xffff;
  
}

void ioShortWrite(unsigned long addr,
		  unsigned short val)
{
  unsigned long newVal ;
  newVal = pack16lsb(val, val) ;
  
  while (MMIO(BIU_STATUS) & 0x5) ;
  MMIO(IO_ADR) = addr;
  MMIO(IO_DATA) = newVal ;
  switch (addr & 0x2) {
  case 0:
    MMIO(IO_CTL) = 0x0c ;
    break ;
  case 2:
    MMIO(IO_CTL) = 0x03 ;
    break ;
  }
  while (MMIO(BIU_STATUS) & 0x4) ;
  MMIO(BIU_STATUS) |= 0x8 ;

  return ;
}

unsigned long
ioLongRead(unsigned long addr)
{
  unsigned long newVal ;

  while (MMIO(BIU_STATUS) & 0x5) ;
  MMIO(IO_ADR) = addr;
  MMIO(IO_CTL) = 0x10 ;
  while (MMIO(BIU_STATUS) & 0x4) ;
  newVal = MMIO(IO_DATA) ;
  MMIO(BIU_STATUS) |= 0x8 ;
  return (newVal);
  
}

void
ioLongWrite(unsigned long addr,
	    unsigned long val)
{
  while (MMIO(BIU_STATUS) & 0x5) ;
  MMIO(IO_ADR) = addr;
  MMIO(IO_DATA) = val ;
  MMIO(IO_CTL) = 0x00 ;
  while (MMIO(BIU_STATUS) & 0x4) ;
  MMIO(BIU_STATUS) |= 0x8 ;

  return ;
}

⌨️ 快捷键说明

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