免费注册 查看新帖 |

Chinaunix

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

请问一个IO端口映射的问题!!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-01-06 22:18 |只看该作者 |倒序浏览
以下问题均是指X86平台
    我在看LDD3时了解到外设的内存和端口都可以映射到RAM的地址空间。如果没理解错外设的端口应该用void *ioport_map(unsiged long port,unsigned int count)映射的到AM地址空间,而外设内存应用struct resource *request_mem_region(unsigned long start,unsigned long len,char* name)。我看了一下源代码,ioport-map只是把外设端口+128K这样来完成映射,因此当使用ioread8这样的函数时可以判断出是IO端口还是IO内存以分别使用不同的指令。后观察LDD3中short模块的源码,发现在映射IO端口时用的是request-mem-region而不是ioport_map,一直搞不清楚这样是否会有问题?

论坛徽章:
0
2 [报告]
发表于 2007-01-09 09:28 |只看该作者
看看这一段:

9.4.3. Ports as I/O Memory
Some hardware has an interesting feature: some versions use I/O ports, while others use I/O memory. The registers exported to the processor are the same in either case, but the access method is different. As a way of making life easier for drivers dealing with this kind of hardware, and as a way of minimizing the apparent differences between I/O port and memory accesses, the 2.6 kernel provides a function called ioport_map:

void *ioport_map(unsigned long port, unsigned int count);


This function remaps count I/O ports and makes them appear to be I/O memory. From that point thereafter, the driver may use ioread8 and friends on the returned addresses and forget that it is using I/O ports at all.

This mapping should be undone when it is no longer needed:

void ioport_unmap(void *addr);


These functions make I/O ports look like memory. Do note, however, that the I/O ports must still be allocated with request_region before they can be remapped in this way.

论坛徽章:
0
3 [报告]
发表于 2007-01-09 10:58 |只看该作者
可能是我对这段代码理解有误:
if (!use_mem) {
                if (! request_region(short_base, SHORT_NR_PORTS, "short")) {
                        printk(KERN_INFO "short: can't get I/O port address 0x%lx\n",
                                        short_base);
                        return -ENODEV;
                }

        } else {
                if (! request_mem_region(short_base, SHORT_NR_PORTS, "short")) {
                        printk(KERN_INFO "short: can't get I/O mem address 0x%lx\n",
                                        short_base);
                        return -ENODEV;
                }

                /* also, ioremap it */
                short_base = (unsigned long) ioremap(short_base, SHORT_NR_PORTS);
                                //这里我认为应该用ioport_map
                /* Hmm... we should check the return value */
        }
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP