免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 6507 | 回复: 12
打印 上一主题 下一主题

PCI Configuration Space的一个小问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-04 21:49 |只看该作者 |倒序浏览
PCI Configuration Space中的那6个内存/IO基址寄存器中的值是谁写入的?硬件还是软件?
如果是硬件的话是不是PCI总线?
如果是软件的话是BIOS还是驱动,值是否可以再分配?分配的代码是怎么写的?谢谢

论坛徽章:
0
2 [报告]
发表于 2009-11-05 01:35 |只看该作者
下面是我的理解,有可能不对。

硬件在生产的时候写入需要地址空间的大小,比如128 byte 还是256 byte。然后在系统初始化的时候,应该是BIOS 或者OS会读取这个数值,然后分配一段空间。代码怎么写的就不清楚了。可以看看LINUX PCI相关部分。

论坛徽章:
0
3 [报告]
发表于 2009-11-05 02:22 |只看该作者
一些参考:
http://docs.sun.com/app/docs/doc ... -28?l=zh&a=view
The PCI configuration space consists of up to six 32-bit base address registers for each device. These registers provide both size and data type information. System firmware assigns base addresses in the PCI address domain to these registers.

http://baike.baidu.com/view/2815.htm
二、即插即用的实现
  所谓即插即用,是指当板卡插入系统时,系统会自动对板卡所需资源进行分配,如基地址、中断号等,并自动寻找相应的驱动程序。而不象旧的ISA板卡,需要进行复杂的手动配置。
  实际的实现远比说起来要复杂。在PCI板卡中,有一组寄存器,叫"配置空间"(Configuration Space),用来存放基地址与内存地址,以及中断等信息。
  以内存地址为例。当上电时,板卡从ROM里读取固定的值放到寄存器中,对应内存的地方放置的是需要分配的内存字节数等信息。操作系统要跟据这个信息分配内存,并在分配成功后把相应的寄存器中填入内存的起始地址。这样就不必手工设置开关来分配内存或基地址了。对于中断的分配也与此类似。

http://en.wikipedia.org/wiki/PCI_Configuration_Space
When a read to a specified BDF succeeds, the BIOS or OS programs the memory and port addresses into the PCI devices' on-chip memory. These addresses stay valid as long as the system remains turned on. On power off, all these settings are lost and on the next system boot, the configuration procedure is repeated all over again.

论坛徽章:
0
4 [报告]
发表于 2009-11-05 10:36 |只看该作者
原帖由 accessory 于 2009-11-5 02:22 发表 System firmware assigns base addresses in the PCI address domain to these registers.


也就是说系统固件分配的喽,卡插入后就不能更改了

论坛徽章:
0
5 [报告]
发表于 2009-11-05 11:08 |只看该作者
On all IBM PC-compatible machines, BARs are assigned by the BIOS. Linux simply scans through the buses and records the BAR values.

Some MIPS boards adopt similar approaches, where BARs are assigned by firmware. However, the quality of BAR assignment by firmware vary quite a bit. Some firmware simply assigns BARs to on-board PCI devices and ignore all add-on PCI cards. In that case, Linux cannot solely rely on the firmware's assignment.

There is another issue of depending on the firmware assignment. You need to stick with the address range setup by the firmware. In other words, if the firmware assigns PCI memory space from 0x10000000 to 0x14000000, you cannot easily move it to a different address space somewhere else in Linux.

There three ways to possibly fix this:
The first way is to fix the BAR assignment manually in your board setup routine. This only works if your board does not have a PCI slot to plug in an arbitrary PCI card. You need to carefully examine the existing PCI resource assignment done by firmware so that you do not assign overlapping address ranges.
The second way is to do a complete PCI resource assignment before Linux starts PCI bus scanning. In other words, we discard any PCI resource assignment done in firmware, if there is any, and do a new assignment by ourselves. This approach gives us complete control over the address range and resource allocation. With the CONFIG_PCI_AUTO option used in 'arch/mips/config-shared.in' and 'arch/mips/kernel/pci_auto.c' file, it turns out to be quite easy to do. This approach is the focus of this chapter.

晕了,都可以……

论坛徽章:
0
6 [报告]
发表于 2009-11-05 11:40 |只看该作者
ls的是从哪里引用过来的?给个连接?

论坛徽章:
0
7 [报告]
发表于 2009-11-05 11:40 |只看该作者
bios可以写,但是linux中并没有使用bios的功能,完全是linux自己通过io地址写入的。
可以看看linux内核情景分析,pci那章

论坛徽章:
0
8 [报告]
发表于 2009-11-05 12:08 |只看该作者
我觉得对于使用了ACPI的系统,接口会有些不同。不过基本原理应该一样。

论坛徽章:
0
9 [报告]
发表于 2009-11-05 16:39 |只看该作者
原帖由 accessory 于 2009-11-5 11:40 发表
ls的是从哪里引用过来的?给个连接?

http://www.linux-mips.org/wiki/P ... assignment_in_Linux

论坛徽章:
0
10 [报告]
发表于 2009-12-31 09:38 |只看该作者
原帖由 emmoblin 于 2009-11-5 11:40 发表
bios可以写,但是linux中并没有使用bios的功能,完全是linux自己通过io地址写入的。
可以看看linux内核情景分析,pci那章

有的东西,不能通过io地址去访问
高地址需要ACPI去访问,比如AER

具体可以看看内核2.6.16和2.6.27的内核的pci_read_config_dword等函数的具体实现。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP