-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[bsp/milkv 仅用于讨论-后续拆分提交]为后续使用ioremap做准备 #9120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
9871819
0dd4ceb
e66b670
1035b88
9cc9e56
36fb2eb
c40294c
1b6ec69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
不过我这个修改建议影响面可能会比较大,需要 @BernardXiong 熊大评估一下是否可以。 #ifdef RT_USING_SMART
void *rt_ioremap_early(void *paddr, size_t size);
void *rt_ioremap(void *paddr, size_t size);
void *rt_ioremap_nocache(void *paddr, size_t size);
void *rt_ioremap_cached(void *paddr, size_t size);
void *rt_ioremap_wt(void *paddr, size_t size);
void rt_iounmap(volatile void *addr);
extern void *rt_ioremap_start;
extern size_t rt_ioremap_size;
#else
#define rt_ioremap_early
#define rt_ioremap(paddr, size) (paddr)
#define rt_ioremap_nocache(paddr, size) (paddr)
#define rt_ioremap_cached(paddr, size) (paddr)
#define rt_ioremap_wt(paddr, size) (paddr)
#define rt_iounmap(addr)
#endif // RT_USING_SMART There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. arm64 那边非 smart 也会使用 ioremap API。详细参考 DD2.0 的实现。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
哦,是不是说 ioremap 的 API 是否使用取决于是否开启了 mmu,即 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ioremap 确实依赖于 mmu,但是是否启用应该是偏软件层面的选择。如果整体驱动设计上就是基于运行时配置,动态且灵活的,比如 DD2.0 的实现,那么选择 ioremap 就是必然的(因为编译期是不能确定 MMIO 空间的)。否则,就像大多数 rtos 的实现,io 地址访问就是 1:1 线性映射的空间。那确实没必要使用这个功能。 所以是否使用真正的 ioremap 可以单独做一个 Kconfig,由软件来配置。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
我目前对 ioremap 的理解可能有些局限,基于这个 pr 要做的事情来看我的理解就是在开启 mmu 后,我们需要将 io 的物理地址映射到虚拟地址才能访问。那么我的疑问是,难道这个不是开启 mmu 后必选的吗?难道还有什么情况下开了 mmu 后我们依然可以直接用物理地址来访问 io? 此外,我对 @polarvid 上面所说的 ”如果整体驱动设计上就是基于运行时配置,动态且灵活的,比如 DD2.0 的实现,那么选择 ioremap 就是必然的“ 这段描述还不太理解,以及 dd2.0 是什么我还不了解,能否再详细说明一下?这里的 ”运行时配置“ 和 io 地址 remap 是什么关系? Thanks, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 给libcpu的nommu都补充一份ioremap.h是最方便的了 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
没看懂什么意思啊 :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ioremap 不是创建虚拟地址映射唯一的方法。具体来说内核支持线性映射和非线性映射,ioremap 从属于非线性映射。因为有两种算法,所以才说选择 ioremap 是软件决定的。更具体地说,选择什么方式是设备模型的设计决定的,所以才提到 DD2.0 框架。 至于为什么、是什么,说来话长了…… There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以在支持mmu这类芯片的驱动里都用上ioremap接口,至于咋映射就交给接口决定,情况复杂了驱动里处理起来麻烦 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dd 2.0,指的是device driver v2.0,相比较原device driver而言。主要来说,它尝试使用设备树了。 至于ioremap怎么怎么着的,我也都弄得不太清楚了。对于ioremap,我的建议是能理顺,逻辑上通顺。反逻辑的就很别扭。 "在开启 mmu 后,我们需要将 io 的物理地址映射到虚拟地址才能访问。" 从这个角度来说,是建议当使用了mmu时,就需要有一份ioremap的,即使这份地址映射是 1:1 的。不知道大家对这份语义是否认同 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include <rtconfig.h> | ||
|
||
#ifdef RT_USING_SMART | ||
#include <ioremap.h> | ||
#else | ||
#define rt_ioremap(a, s) (a) | ||
#endif |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 和上面对 #ifdef BSP_USING_UART0
static struct hw_uart_device _uart0_device;
#endif
......
int rt_hw_uart_init(void)
{
....
#ifdef BSP_USING_UART0
pinmux_config(BSP_UART0_RX_PINNAME, UART0_RX, pinname_whitelist_uart0_rx);
pinmux_config(BSP_UART0_TX_PINNAME, UART0_TX, pinname_whitelist_uart0_tx);
BSP_INSTALL_UART_DEVICE(0);
uart->hw_base = (rt_size_t)rt_ioremap(UART0_BASE, 0x10000);
uart->irqno = UART0_IRQ;
#endif
......
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,12 +23,9 @@ | |
#define PAD_MIPI_TXM0__MIPI_TXM0 0 | ||
#define PAD_MIPI_TXP0__MIPI_TXP0 0 | ||
|
||
#if defined(ARCH_ARM) | ||
extern rt_ubase_t pinmux_base_ioremap(void); | ||
#define PINMUX_BASE pinmux_base_ioremap() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 对 所以我这里建议:是否可以将 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PINMUX_BASE这个暂时保留,这次提交主要是想不太多修改原来代码基础上使用ioremap,效率问题可以后面修改 |
||
#else | ||
#define PINMUX_BASE 0x03001000 | ||
#endif /* defined(ARCH_ARM) */ | ||
|
||
#define PINMUX_MASK(PIN_NAME) FMUX_GPIO_FUNCSEL_##PIN_NAME##_MASK | ||
#define PINMUX_OFFSET(PIN_NAME) FMUX_GPIO_FUNCSEL_##PIN_NAME##_OFFSET | ||
#define PINMUX_VALUE(PIN_NAME, FUNC_NAME) PIN_NAME##__##FUNC_NAME | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议把这个文件重命名为 另外,在内核主线树外,我和 @flyingcys 在做一些 pinmux 的开发(感兴趣可以参考 https://github.com/flyingcys/rt-thread/pull/21),只是还没有提交主线上来,相关文件名也是取的 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <rtdef.h> | ||
#include "drv_ioremap.h" | ||
|
||
static rt_ubase_t pinmux_base = RT_NULL; | ||
|
||
rt_ubase_t pinmux_base_ioremap(void) | ||
{ | ||
if (pinmux_base == RT_NULL) | ||
{ | ||
pinmux_base = (rt_size_t)rt_ioremap((void*)0x03001000, 0x1000); | ||
} | ||
|
||
return pinmux_base; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
写法建议修改为如下方式。理由,没有必要赋值两次,定义时直接放 BSS,可以有助于减小 bin 文件 size