-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
【dd2.0】Support Open Firmware API #7788
Conversation
We add the device name and id set api in DM, now driver could set name like sprintf without know how many devices it is. The misc.h and byteorder.h add some macros to developers that they always use in drivers. Signed-off-by: GuEe-GUI <[email protected]>
Support aarch64 rt_hw_atomic_* api. Add atomic implemente by rt_atomic api: rt_atomic_dec_and_test rt_atomic_fetch_add_unless rt_atomic_add_unless rt_atomic_inc_not_zero Signed-off-by: GuEe-GUI <[email protected]>
Add reference with rt_atomic in resources' put/get management. Add bitmap operator base on rt_ubase_t. Add hashmap for key->data map management. Signed-off-by: GuEe-GUI <[email protected]>
We support OFW API to replace fdt old API, and add IRQ, IO, Platform-Bus, CPUs ... OFW node contorl. To support work with Device Tree or ACPI in drivers that use IRQ, we make a programmable interrupt controller driver's model. Signed-off-by: GuEe-GUI <[email protected]>
请使用 https://github.com/mysterywolf/formatting 格式化一下格式 |
#7789 这个合并了之后 CI就能过了,到时候重新提交一下 |
已合并 |
* Date Author Notes | ||
* 2023-04-20 ErikChan the first version | ||
*/ | ||
|
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.
关于dm的缩写,要能找到地方知道是什么意思。
len = rt_strlen(name) - 1; | ||
name += len; | ||
|
||
while (len --> 0) |
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.
这里的代码格式要注意,--是需要跟len变量组合的,所以得靠拢len而不是靠拢>。另外尽量避免写出多个运算符连续出现在一起的代码,一定要这么写加括号吧
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.
是的, 这两天会把这些建议优化一次
|
||
while (len --> 0) | ||
{ | ||
if (*name < '0' || *name > '9') |
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.
这个if和里面的while逻辑没看懂,这里判断是非数字就进if,while里又把他当数字来用。
这种代码要写注释呢,感觉你是默认了name是一种特殊的格式:
name指向的字符串最后是数字?既然默认了特殊格式就没必要判断了吧?既然要判断就说明他格式可能出错,既然会出错那现在的检查手段完全不够,while里调过第一个非数字后就一定是数字了?
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.
这个函数就是为了获取 dm 的注册的设备名称,名称只能是 rtc 或者 rtc0,rtc123 这种格式,当我们从字符串末尾向前开始扫描到非数字的字符的时候,再继续向后 +1 后开始读取数字,如果是 rtc 这种格式,自然不会扫描到数字,返回的就是 0 了。
#define rt_cpu_to_le32(x) __builtin_bswap32(x) | ||
#define rt_cpu_to_le64(x) __builtin_bswap64(x) | ||
#else | ||
#define rt_cpu_to_be16(x) __builtin_bswap16(x) |
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.
所有编译器都有这个符号吗?
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.
这个符号目前只有 GCC 和 Clang 支持,但是 DM 平台目前支持的平台芯片基本只使用 GCC 和 Clang。
#include <drivers/misc.h> | ||
#include <drivers/byteorder.h> | ||
|
||
#ifndef RT_CPUS_NR |
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.
这个宏定义让menuconfig自动生成吧,当SMP没配置的时候默认生成1?
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.
是的,因为有些驱动对资源的配置是根据CPU数量来的
#endif | ||
#define RT_BITS_PER_LONG_LONG 64 | ||
|
||
#define RT_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
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.
这里的1需要限定符号和长度,例如1u、1ul
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.
可以考虑额外提供RT_DIV_ROUND_UP_ULL
return count; | ||
} | ||
|
||
static rt_int32_t ofw_strcmp(const char *cs, const char *ct) |
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.
inline是不是更好?
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.
此处是由于调用ofw_prop_index_of_string的第二个参数需要传入 比较函数 的指针,所以没使用 inline,而 rt_strcmp,rt_strncmp 和 strcmp,strncmp 这些函数由于 rtthread.h 宏干扰不能直接找到定义(有未定义函数警告),所以独立设置了个函数用于间接跳转。
|
||
#include "ofw_internal.h" | ||
|
||
struct rt_fdt_earlycon fdt_earlycon rt_section(".bss.noclean.earlycon"); |
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.
看了一下没被外部引用加static
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.
此处后续如果 earlycon 框架确实没用到会加上 static
|
||
rt_inline rt_err_t commit_memregion(const char *name, rt_uint64_t base, rt_uint64_t size, rt_bool_t is_reserved) | ||
{ | ||
return rt_fdt_commit_memregion_early(&(rt_region_t) |
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.
不建议写这种偷懒的代码
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.
这种写法确实少见,如果存在安全隐患会后续可以改成声明局部变量的方式。
struct fdt_info | ||
{ | ||
/* Always "/", because we save "ofw" information in root node. */ | ||
char name[sizeof("/")]; |
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.
用sizeof定义数组只在C99标准并且支持可变长度数组规范下才支持吧?
换编译器会翻车?
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.
C98 已经 out 了吧,但是此处其实只要有 2 字节就够了,不会翻车的
拉取/合并请求描述:(PR description)
[
AArch64: support hardware atomic
Utilities/libadt: support adt API for DM
Drivers: Support Open Firmware API and model of PIC
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0
代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up