ioremap returns 空
ioremap returns NULL
我正在尝试为 Raspberry PI 创建自定义 UART 驱动程序。
我尝试 ioremap MMIO。但是 ioremap
returns 总是 NULL
.
#define UART_REG_BASE_ADDR 0x7E20100
pUart = ioremap(UART_REG_BASE_ADDR, 1024);
if (pUart==NULL)
{
printk("Couldn't remap UART MMIO\n");
return -EIO;
}
dmesg
转储如下:
[ 2906.579848] CPU: 0 PID: 4983 Comm: insmod Tainted: G D W O 3.18.5+ #1
[ 2906.590783] [<c0014b64>] (unwind_backtrace) from [<c00120ec>] (show_stack+0x20/0x24)
[ 2906.614046] [<c00120ec>] (show_stack) from [<c0549008>] (dump_stack+0x20/0x28)
[ 2906.624803] [<c0549008>] (dump_stack) from [<c0022620>] (warn_slowpath_common+0x7c/0x9c)
[ 2906.647925] [<c0022620>] (warn_slowpath_common) from [<c002266c>] (warn_slowpath_null+0x2c/0x34)
[ 2906.668656] [<c002266c>] (warn_slowpath_null) from [<c001a888>] (__arm_ioremap_pfn_caller+0x240/0x25c)
[ 2906.691936] [<c001a888>] (__arm_ioremap_pfn_caller) from [<c001a934>] (__arm_ioremap_caller+0x68/0x70)
[ 2906.713171] [<c001a934>] (__arm_ioremap_caller) from [<c001a3d0>] (__arm_ioremap+0x24/0x2c)
[ 2906.735043] [<c001a3d0>] (__arm_ioremap) from [<bf19c028>] (hello_init+0x28/0x88 [domotx])
[ 2906.755780] [<bf19c028>] (hello_init [domotx]) from [<c000873c>] (do_one_initcall+0x94/0x1e4)
[ 2906.778165] [<c000873c>] (do_one_initcall) from [<c0087e70>] (load_module+0x1848/0x1e38)
[ 2906.799410] [<c0087e70>] (load_module) from [<c008854c>] (SyS_init_module+0xec/0xf0)
[ 2906.822660] [<c008854c>] (SyS_init_module) from [<c000e980>] (ret_fast_syscall+0x0/0x48)
[ 2906.844558] ---[ end trace c7cdd8b3d5007a1b ]---
[ 2906.856382] Couldn't remap UART MMIO
我做错了什么?
我找到了上述问题的解决方案。实际上解决方案有两个方面:
- BCM2835 数据表未在其数据表中宣传物理地址:
外围设备的物理地址范围从 0x20000000 到 0x20FFFFFF。外设的总线地址设置为映射到从 0x7E000000 开始的外设总线地址范围。因此,在总线地址 0x7Ennnnnn 处公布的外设在物理地址 0x20nnnnnn 处可用。
- 数据表中有错字:
PL011 USRT 映射到基地址 0x7E20100。 必须 PL011 USRT 映射到基地址 0x7E201000。
我正在尝试为 Raspberry PI 创建自定义 UART 驱动程序。
我尝试 ioremap MMIO。但是 ioremap
returns 总是 NULL
.
#define UART_REG_BASE_ADDR 0x7E20100
pUart = ioremap(UART_REG_BASE_ADDR, 1024);
if (pUart==NULL)
{
printk("Couldn't remap UART MMIO\n");
return -EIO;
}
dmesg
转储如下:
[ 2906.579848] CPU: 0 PID: 4983 Comm: insmod Tainted: G D W O 3.18.5+ #1
[ 2906.590783] [<c0014b64>] (unwind_backtrace) from [<c00120ec>] (show_stack+0x20/0x24)
[ 2906.614046] [<c00120ec>] (show_stack) from [<c0549008>] (dump_stack+0x20/0x28)
[ 2906.624803] [<c0549008>] (dump_stack) from [<c0022620>] (warn_slowpath_common+0x7c/0x9c)
[ 2906.647925] [<c0022620>] (warn_slowpath_common) from [<c002266c>] (warn_slowpath_null+0x2c/0x34)
[ 2906.668656] [<c002266c>] (warn_slowpath_null) from [<c001a888>] (__arm_ioremap_pfn_caller+0x240/0x25c)
[ 2906.691936] [<c001a888>] (__arm_ioremap_pfn_caller) from [<c001a934>] (__arm_ioremap_caller+0x68/0x70)
[ 2906.713171] [<c001a934>] (__arm_ioremap_caller) from [<c001a3d0>] (__arm_ioremap+0x24/0x2c)
[ 2906.735043] [<c001a3d0>] (__arm_ioremap) from [<bf19c028>] (hello_init+0x28/0x88 [domotx])
[ 2906.755780] [<bf19c028>] (hello_init [domotx]) from [<c000873c>] (do_one_initcall+0x94/0x1e4)
[ 2906.778165] [<c000873c>] (do_one_initcall) from [<c0087e70>] (load_module+0x1848/0x1e38)
[ 2906.799410] [<c0087e70>] (load_module) from [<c008854c>] (SyS_init_module+0xec/0xf0)
[ 2906.822660] [<c008854c>] (SyS_init_module) from [<c000e980>] (ret_fast_syscall+0x0/0x48)
[ 2906.844558] ---[ end trace c7cdd8b3d5007a1b ]---
[ 2906.856382] Couldn't remap UART MMIO
我做错了什么?
我找到了上述问题的解决方案。实际上解决方案有两个方面:
- BCM2835 数据表未在其数据表中宣传物理地址: 外围设备的物理地址范围从 0x20000000 到 0x20FFFFFF。外设的总线地址设置为映射到从 0x7E000000 开始的外设总线地址范围。因此,在总线地址 0x7Ennnnnn 处公布的外设在物理地址 0x20nnnnnn 处可用。
- 数据表中有错字: PL011 USRT 映射到基地址 0x7E20100。 必须 PL011 USRT 映射到基地址 0x7E201000。