-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
plat/drivers: Add two configurations to ns16550 #985
Conversation
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.
Hi @zhxj9823, thanks for that! 🚀 Besides the comments below, since this change breaks backwards compatibility, it is important to mention this in the commit message. Moreover, please include in the commit message justification for that, ie a reference to the spec.
Hi, @zhxj9823. This has been marked as a draft PR. What needs to happen to make this a full PR? |
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.
@zhxj9823 , could you also elaborate what is the register shift? As someone with little knowledge about UART / NS16550, I would benefit from this information as part of the commit message. Likely others as well.
Personally I am against trivialization (in general), it is expected that the audience has some familiarity with the topic. Look at the commit history of other OSes for example. Besides, where would you draw the line. And this is a simple concept, more complex topics would require way more elaborate explanations. Saying that, if you really think it's necessary, one sentence is okay 😛 |
e038647
to
e2d8a65
Compare
@zhxj9823 thanks for the updates. As requested by @razvand please remove the One small thing that could be improved could be explicitly setting the default reg_shift:
This is of course not required for functionality, but makes it more clear when reading the code that the default value is derived by the spec. Other than that, from my side it looks good 👍🏼 @kubanrob I am adding as a reviewer since that change affects you. |
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.
@michpappas I investigated for our plattform and do not see problems with switching to 8bit register-width in this driver. On the other hand, having the register-width configurable is will also not hurt anybody, and the reduces the risk for anybody currently using this driver.
Anyways any new variable should also be properly initialized if early boot UART is activated.
plat/drivers/uart/ns16550.c
Outdated
static uint32_t ns16550_reg_shift = 0; /* device-tree spec v0.4 Sect. 4.2.2 */ | ||
static uint32_t ns16550_reg_width = 1; /* 8-bit register width by default */ |
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.
These variables are missing for the early uart (see the lines above). It would make sense to introduce the corresponding config options (default values matching the device tree ones).
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.
Good point, thanks! 👍🏼 @zhxj9823 will you please update to add these?
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.
I have added the config options. Please check if these options work fine.
It also raises the question of how to switch between pl011
and ns16550
as the early debug console.
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.
I have added the config options. Please check if these options work fine.
I think these two options should not be limited to EARLY_UART
, but should be overriding the defaults when set, unconditionally. That would allow the driver to work correctly in any future platforms that do not use dts.
The priority should therefore be:
- dts (overrides everything)
- Kconfig (if set override defaults)
- Defaults (according to the spec)
It also raises the question of how to switch between pl011 and ns16550 as the early debug console.
For that we should merge the options of the different drivers into a single one, and most likely also consider an option in the command line, but this is outside the scope of this PR.
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.
I think these two options should not be limited to
EARLY_UART
, but should be overriding the defaults when set, unconditionally. That would allow the driver to work correctly in any future platforms that do not use dts.The priority should therefore be:
- dts (overrides everything)
- Kconfig (if set override defaults)
- Defaults (according to the spec)
I update the patch. But I think it would be better if the two configs depend on something like uart_ns16550
.
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.
I had a brief look on how the reg-shift and width for the earlycon
are specified on linux. There these are not compiled in, but rather derived from the command-line options:
- https://www.kernel.org/doc/html/v4.14/admin-guide/kernel-parameters.html
- https://elixir.bootlin.com/linux/latest/source/drivers/tty/serial/earlycon.c#L93
The latter derives the regshift from the mmio width, ie 0 by default, 1 for MMIO16, and 2 for MMIO32 access. Right now we use 16-bit access and a regshift of 2 which doesn't make sense. @kubanrob should that be 32-bit access instead? Also would the command line be a valid option for earlycon in your case, assuming we implemented that? I imagine that since it's used on linux, it should be no problem for Unikraft.
Edit: Actually nevermind, as right now libukparam
only supports paramters in the the form of <libname>.<paramname>=
, so parameters without a scope like earlycon=
or console=
won't work.
e7b227d
to
c668d9c
Compare
c668d9c
to
226c0cc
Compare
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.
@zhxj9823, @michpappas, this is OK from my side. I've tested it together with #1048 and it works OK.
Reviewed-by: Razvan Deaconescu razvand@unikraft.io
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.
Looks good to me, thanks you @zhxj9823!
Reviewed-by: Robert Kuban robert.kuban@opensynergy.com
@zhxj9823 now that the parent PR has been merged, please rebase to |
The register shift of ns16550 is hard-coded in the driver, but it does not match the hardware on some platforms. The device-tree specification has a property "reg-shift" to describe the register shift of a device. To match the specification, the register shift of ns16550 is retrieved from the device tree instead. If no such property is found, the default value 0 is used. The register width of ns16550 varies on different platforms. u-boot uses a reg-io-width property in the device tree to determine it. If no such property is found, the default value 1 is used. The read and write macros are replaced by functions with the same name. This patch also adds the corresponding configurations to override the values when dts does not specify them. These two configurations break the compatibility of the driver. To keep the compatibility, the device tree should contain these properties or set them in configurations. Signed-off-by: Xingjian Zhang <zhxj9823@qq.com>
226c0cc
to
cee85ff
Compare
✅ Checkpatch passed Beep boop! I ran Unikraft's
|
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.
Thank you @zhxj9823 🚀
Reviewed-by: Michalis Pappas michalis@unikraft.io
Approved-by: Michalis Pappas michalis@unikraft.io
Prerequisite checklist
checkpatch.uk
on your commit series before opening this PR;Base target
ARM64
kvm
Additional configuration
Description of changes
The register shift of ns16550 is hard-coded in the driver, but it does not match the hardware on some platforms. The device-tree specification has a property "reg-shift" to describe the register shift of a device.
To match the specification, the register shift of ns16550 is retrieved from the device tree instead. If no such property is found, the default value 0 is used.
The register width of ns16550 varies on different platforms. u-boot uses a reg-io-width property in the device tree to determine it. If no such property is found, the default value 1 is used. The read and write macros are replaced by functions with the same name.
These two configurations break the compatibility of the driver. To keep the compatibility, the device tree should contain these properties.