免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: sherf
打印 上一主题 下一主题

PCI网卡的MAC地址 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2009-11-03 13:07 |只看该作者
要用io来读。10楼的方法不对。
另外,你确定拿到的iobase是对的么?可以打印出来看看具体数值。

论坛徽章:
0
12 [报告]
发表于 2009-11-03 13:21 |只看该作者
又想了下。怎么读要看你的设备是配制成 io map or memory map. 如果是io map,那用9楼的方法,反之用10楼的。
我看 qemu rtl8139的实现文件里,2种都支持。bochs就不清楚了。

论坛徽章:
0
13 [报告]
发表于 2009-11-03 13:22 |只看该作者
原帖由 accessory 于 2009-11-3 13:07 发表
要用io来读。10楼的方法不对。
另外,你确定拿到的iobase是对的么?可以打印出来看看具体数值。


accessory,

用哪个IO端口读? 如果是用io的方法之前我也试过(9楼的代码),但出不来结果(数据不对)。顺便问一句,我之前的代码(9楼)对吗 ?由于是用bochs调试,很多东西我都不是很确定.......

另,iobase我打印过出来,是有数值的,但对不对我也不知道怎样验证。

论坛徽章:
0
14 [报告]
发表于 2009-11-03 15:07 |只看该作者

回复 #13 sherf 的帖子

有人知道吗?mac这东西真难弄...........

论坛徽章:
0
15 [报告]
发表于 2009-11-04 00:07 |只看该作者
lz,你到底是在什么环境下编程的?什么OS?自己写的OS?PCI 初始化这部分一般是OS去做的。你程序运行的时候OS还没跑起来?
如果没有OS初始化过PCI的话,那你要自己读PCI 设备的 BASE ADDR REGISTER。找出来它是IO MAP OR MEMORY MAP。需要多大,然后自己分配个空间给它。我以前给你的连接里写的还算清楚的。不知道你看了没有。下面我把相关的直接贴出来。


http://tldp.org/LDP/tlk/dd/pci.html
Finding Out How Much PCI I/O and PCI Memory Space a Device Needs
Each PCI device found is queried to find out how much PCI I/O and PCI Memory address space it requires. To do this, each Base Address Register has all 1's written to it and then read. The device will return 0's in the don't-care address bits, effectively specifying the address space required.

There are two basic types of Base Address Register, the first indicates within which address space the devices registers must reside; either PCI I/O or PCI Memory space. This is indicated by Bit 0 of the register. Figure  6.10 shows the two forms of the Base Address Register for PCI Memory and for PCI I/O.

To find out just how much of each address space a given Base Address Register is requesting, you write all 1s into the register and then read it back. The device will specify zeros in the don't care address bits, effectively specifying the address space required. This design implies that all address spaces used are a power of two and are naturally aligned.

For example when you initialize the DECChip 21142 PCI Fast Ethernet device, it tells you that it needs 0x100 bytes of space of either PCI I/O or PCI Memory. The initialization code allocates it space. The moment that it allocates space, the 21142's control and status registers can be seen at those addresses.

Allocating PCI I/O and PCI Memory to PCI-PCI Bridges and Devices
Like all memory the PCI I/O and PCI memory spaces are finite, and to some extent scarce. The PCI Fixup code for non-Intel systems (and the BIOS code for Intel systems) has to allocate each device the amount of memory that it is requesting in an efficient manner. Both PCI I/O and PCI Memory must be allocated to a device in a naturally aligned way. For example, if a device asks for 0xB0 of PCI I/O space then it must be aligned on an address that is a multiple of 0xB0. In addition to this, the PCI I/O and PCI Memory bases for any given bridge must be aligned on 4K and on 1Mbyte boundaries respectively. Given that the address spaces for downstream devices must lie within all of the upstream PCI-PCI Bridge's memory ranges for any given device, it is a somewhat difficult problem to allocate space efficiently.

论坛徽章:
5
16 [报告]
发表于 2009-11-04 09:13 |只看该作者
找到该卡的编程手册吧

论坛徽章:
0
17 [报告]
发表于 2009-11-04 09:55 |只看该作者
原帖由 accessory 于 2009-11-4 00:07 发表
lz,你到底是在什么环境下编程的?什么OS?自己写的OS?PCI 初始化这部分一般是OS去做的。你程序运行的时候OS还没跑起来?
如果没有OS初始化过PCI的话,那你要自己读PCI 设备的 BASE ADDR REGISTER。找出来它是 ...


accessory,

你的意思是:如果不使用操作系统资源(像目前我是通过其他的启动程序而没进入任何操作系统)的话,要读取MAC地址就只能从EPPROM入手,而将MAC地址映射入IO地址空间(IOADDR头6个字节)的任务是操作系统去完成的(即我目前是要自己编程实现的)。是这样吗?

论坛徽章:
0
18 [报告]
发表于 2009-11-04 17:14 |只看该作者

回复 #15 accessory 的帖子

accessory,

谢谢你之前的回复,我已拿到MAC地址了

论坛徽章:
0
19 [报告]
发表于 2009-11-04 19:15 |只看该作者
关注下

论坛徽章:
0
20 [报告]
发表于 2009-11-05 01:29 |只看该作者
怎么拿到的?换了QEMU就好了?又是BOCHS的问题?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP