跳至主要内容

【转】PCI空间映射的永久解决方案

最近忙到要命,也不知道在忙什么,甚至连游戏都没有时间玩了,所以,也没有时间来调试这个一揽子的解决方案。 虽然没有调试过,但我认为应该是对的,毕竟是从原来的工程中改出来的,问题不大,呵呵。

现在贴出来,表示我这个月还是写了一点东西,以后如果有修改就跟在评论上好了,嘿嘿。就这样吧,大家中秋(晚了点)、十一快乐。
#include "vxworks.h"
#include "tasklib.h"
#include "syslib.h"
#include "config.h"
#include "vmlib.h"
#include "drv/pci/pciConfigLib.h"

/*该文件通用于PCI板卡配置
板卡配置的目的就是内存映射。其实这个工作可以由
WindRiver来做。
解决的问题是:
1、每一个板卡都有不同的VID和DID,这样需要一个数组
完成, 也就是说在循环的过程中通过数组访问实
现多个板卡支持。
2、同类型板卡支持。同类型的板卡可能会存在多个实
例。每一个实例都会占用资源,不同的板卡占用的
资源是不同的,需要不同的配置。
3、每一块板卡都有不同的配置空间数量。对于每一个
板卡来说,需要配置的内存空间是不相同的,从一
个到多个不等,中间还有可能跳过一些配置,这就
需要程序可以自动完成配置。
4、内存空间大小不一。不同类型的板卡所需要映射的
内存空间都是不相同的。这时需要计算出内存地址
的容量,这样可以进行设置。
没有解决的问题:
1、该文件并不想为其他程序提供什么方便。提供方便
实际上无可厚非,但是可能会降低通用性。基于这
种考虑,该程序并不为其他程序提供任何方便的接
口。
2、用户需要对文件进行自定义,由于文件的目的是解
决通用性的问题,所以用户需要自己定义板卡的数
量和种类。另外用户需要对BSP进行改动。
3、每一个映射的类型都是VM_STATE_MASK_FOR_ALL和VM_STATE_FOR_PCI。
这个问题目前不知道应如何解决。
*/
#undef xxx_DEBUG /*用于调试,平常不要定义*/
/*这里定义每一个VID和DID*/
#define xxx_VENDOR_ID 0xFFFF
#define xxx_DEV_ID 0xFFFF
#define xxxUNKNOWN 0
#define xxx_MAX_UNITS 2 /*这里以2个卡为例子*/
/*每一个板卡的资源*/
typedef struct xxxResource /* xxx_RESOURCE */
{
int BoardVID;
int BoardDID;
int unitInx;
} xxx_RESOURCE;
/*板卡资源的定义,这里以相同的板卡为例子
板卡如果相同的话unitInx逐次递增,如果不同
的话则从零开始*/
LOCAL xxx_RESOURCE xxxRes [xxx_MAX_UNITS] =
{
{xxx_VENDOR_ID, xxx_DEV_ID, 0},
{xxx_VENDOR_ID, xxx_DEV_ID, 1},
};

/*这里就是PCI初始化部分了*/
void xxxPciInit (void)
{
xxx_RESOURCE *pReso;
int pciBus;
int pciDevice;
int pciFunc;
int unit;
int iCommand;
BOOL duplicate;
UINT32 membaseCsr;
UINT32 r_membase;/*用于计算地址映射的空间*/
char irq;
int ix;

for (unit = 0; unit < xxx_MAX_UNITS; unit++)
{
/*寻找板卡*/
if (pciFindDevice (xxxRes[unit].BoardVID, xxxRes[unit].BoardDID,
xxxRes[unit].unitInx, &pciBus, &pciDevice, &pciFunc) != OK)
break;
/* 检查是否重复配置 ,这里应该不会有问题,所以暂时去掉*/
/* pReso = &xxxResources [0];
duplicate = FALSE;
for (ix = 0; ix < xxx_MAX_UNITS; ix++, pReso++)
{
if ((ix != unit) && (pReso->pciBus == pciBus) &&
(pReso->pciDevice == pciDevice) && (pReso->pciFunc == pciFunc))
duplicate = TRUE;
}
if (duplicate) continue;*/
/* 应该是找到了*/
pReso = &xxxRes [unit];
/* PCI_CFG_TYPE can be defined to PCI_CFG_NONE,PC_CFG_AUTO,or PCI_CFG_FORCE.*/
/* 在X86下,BIOS会分配好资源的,所以不需要再配置了,嘿嘿*/
for(ix=0; ix<6; ix++)/*总共是6个地址*/
{
pciConfigInLong (pciBus, pciDevice, pciFunc,
PCI_CFG_BASE_ADDRESS_0 + 0x04 * ix, &membaseCsr); /*读回地址内容*/
/*首先需要判断是内存还是端口,如果不是端口就映射*/
if(!(membaseCsr&PCI_BAR_SPACE_IO))
{
/*首先,需要判断所需内存的大小
根据PCI的规范,将内容写回就可以得到大小*/
pciConfigOutLong (pciBus, pciDevice, pciFunc,
PCI_CFG_BASE_ADDRESS_0 + 0x04 * ix, 0xffffffff);
pciConfigInLong (pciBus, pciDevice, pciFunc,
PCI_CFG_BASE_ADDRESS_0 + 0x04 * ix, &r_membase);
r_membase &= PCI_MEMBASE_MASK; /*现在r_membase就是长度了*/
/*再把地址写回去*/
pciConfigOutLong (pciBus, pciDevice, pciFunc,
PCI_CFG_BASE_ADDRESS_0 + 0x04 * ix, membaseCsr);

membaseCsr &= PCI_MEMBASE_MASK;
#ifdef xxx_DEBUG
/*如果现在是调试阶段,则不用映射,继续下一个*/
printf("\nmemory space is : 0x%x", membaseCsr);
printf("\nlength is : 0x%x", r_membase);
continue;

评论

发表评论

此博客中的热门博文

【转】smb协议栈使用示例

/*  * * uncdownload.c  * *  * * Utility for downloading files from SMB shares using libsmbclient  * *  * * Copyright(C) 2006 Sophos Plc, Oxford, England.  * *  * * This program is free software; you can redistribute it and/or modify it under the terms of the  * * GNU General Public License Version 2 as published by the Free Software Foundation.  * *  * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  * * even the 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  * *  * */ # include < sys / types . h > # include < sys / time . h > # include ...

【转】Ether Types

Ether Types (last updated 2008-09-09) NOTE: Please see [RFC5342] for current information and registration procedures. This registry will be revised soon and will be replaced with up-to-date information. Many of the networks of all classes are Ethernets (10Mb) or Experimental Ethernets (3Mb). These systems use a message "type" field in much the same way the ARPANET uses the "link" field. If you need an Ether Type, contact: IEEE Registration Authority IEEE Standards Department 445 Hoes Lane Piscataway, NJ 08854 Phone +1 732 562 3813 Fax: +1 732 562 1571 Email: <ieee-registration-authority& ieee.org > http://standards.ieee.org/regauth/index.html The following list of EtherTypes is contributed unverified information from various sources. Another list of EtherTypes is maintained by Michael A. Patton and is accessible at: <URL: http://www.cavebear.com/CaveBear/Ethernet/ > <URL: ftp://ftp.cavebear.com/pub/Ethernet-codes > Assign...

【转帖】berkeleyDB安装

我们以redhat9为例开始介绍其安装过程: 从其sleepycat公司官网的下载页 http://dev.sleepycat.com/downloads/releasehistorybdb.html 获得其安装包,现在已经更新到4.4.20.   #tar zxfv db-4.x.tgz   #cd db-4.x/build_unix   1. 如果以gcc编译的话,进行以下操作:   #vi /dist/configure 在最前面添加:CC gcc   #../dist/configure   #make   #make install   默认状态,berkeleyDB的lib和include将被安装到/usr/local/BerkeleyDB/下,需要更改这个路径的话,可以将 #../dist/configure一步加上选项--prefix,例如:#../dist/configure --prefix=/opt/BerkeleyDB.   #vi /etc/ld.so.conf 并将berkeleyDB的lib路径加到该文件的最后一行,这样才能找到并加载它的库文件.ld.so.conf是什么东西?它就是系统动态链接库的配置文件。此文件内,存放着可被LINUX共享的动态链接库所在目录的名字(系统目录/lib,/usr/lib除外),各个目录名间以空白字符(空格,换行等)或冒号或逗号分隔。   #ldconfig   2. 如果以armgcc编译的话,进行以下操作:   先安装armgcc,对我说就是在/mnt/setup/program/FFT/FFT-2410光盘-V3.0/linux开发/linux交叉编译器/tool或者在gmail中附件里armgcc目录下(除了cross-armv4l-qtE-custom-1.5-3mz.i386.rpm,其他都装)   #cp /mnt/setup/program/FFT/FFT-2410光盘-V3.0/linux开发/linux交叉编译器/tool /usr/tmp/   #cd /usr/tmp/tool   #rpm -ivh *   #ldc...