-
Notifications
You must be signed in to change notification settings - Fork 11
[opentitan, usbdev] Create initial usbdev block #180
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
base: ot-9.2.0
Are you sure you want to change the base?
Conversation
b3d7d26
to
49df0bb
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.
I'm not sure why we want to merge a full dummy device.
It seems for now it does nothing really useful(?)
What does this bring vs. the OT_UNIMP device it replaces?
hw/riscv/ot_earlgrey.c
Outdated
// IBEX_DEV_STRING_PROP("ot_id", "usbdev"), | ||
// IBEX_DEV_UINT_PROP("irq-count", 18u), | ||
// IBEX_DEV_UINT_PROP("alert-count", 1u), | ||
IBEX_DEV_UINT_PROP("pclk", OT_EG_USBDEV_CLK_HZ) |
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.
This is an outdated way to configure the clock. USB device should be connected to the clock manager instead (see other peripherals for example, e.g. OT_UART
)
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 you may have commented on the old version of the PR? The current version does not have pclk
anymore. Can you let me know if the code is correct though?
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.
Oops, sorry I missed your comment. New code seems fine.
hw/riscv/ot_earlgrey.c
Outdated
.gpio = IBEXGPIOCONNDEFS( | ||
OT_EG_SOC_GPIO_ALERT(0, 21) | ||
) | ||
// IBEX_DEV_STRING_PROP("ot_id", "usbdev"), |
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.
Dead code to be removed
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 this is a comment on the outdated code
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.
Hum interesting ^^ I will move the PR to draft and set it to ready againa after I fixed everything
hw/riscv/ot_earlgrey.c
Outdated
#include "hw/opentitan/ot_sram_ctrl.h" | ||
#include "hw/opentitan/ot_timer.h" | ||
#include "hw/opentitan/ot_uart.h" | ||
#include "hw/opentitan/ot_usbdev.h" |
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.
Seems in wrong order, see scripts/opentitan/ot-format.sh
Note that we discovered earlier this week that the CI does not fail when this script is called (it is missing some extra commands that are part of the gitlab CI but did not make it to the github version, my mistake)
8048aee
to
48bf161
Compare
6f5515e
to
521a3c0
Compare
OT_EG_SOC_GPIO_SYSBUS_IRQ(16, PLIC, 151), | ||
OT_EG_SOC_GPIO_SYSBUS_IRQ(17, PLIC, 152), | ||
OT_EG_SOC_GPIO_ALERT(0, 21) | ||
// TODO Model sense pin |
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.
Need to remove this comments, the sense pin is modelled as a real pin because it doesn't make sense for a virtual USB bus.
@@ -0,0 +1,35 @@ | |||
/* |
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.
Can we keep a flat, single file hierarchy? This would be more consisten to all other OT implementation as well as QEMU.
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.
The USB driver will be much too big for a single file I think, unless you are happy with 3000+ lines of code in a single file?
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.
Yes, I think it is better (there are several other files that are longer). There is a couple of exceptions (OTP) which is even longer but has fully-generated C file as it was easier to maintain/upgrade as a separate file. They all stands in the same directory though. We try to keep all IPs with the same structure to it is easier to move from one to another. If the file is getting very big once implemented, we can review this policy and split it (in the same directory) if that makes sense; however for now, I think a single file is ok.
|
||
/* VBUS control mode. */ | ||
typedef enum OtUsbdevVbusMode { | ||
OT_USBDEV_VBUS_OVERRIDE, |
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'm not sure to get it, since there is only one value (== 0) in this enum, whatever the value of vbus_mode_str
, vbus_mode is always assigned OT_USBDEV_VBUS_OVERRIDE
.
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.
It's partly explained in usbdev.md
: when we have real USB/IP support, we want to have two modes: one where VBUS is controlled explicitely (independently of the host), and one where VBUS corresponds to host presence (probably the sane default). At the moment we do not have "host" but we still want to control vbus. I can remove that if you want, but it will be added later anyway.
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.
Ok, I get it, although it is a bit weird not to have a defaut non-override value, which could not be selected since you forced it to OVERRIDE through the property anyway.
BTW, as the property is called "vbus-mode", would it not be "override" rather than "vbus-override"? Or since I'm not sure to understand how many "vbus-mode" are planned to be supported, is it not boolean property, i.e. "vbus-override=on/off"?
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.
Yes I think we could make it a boolean property
REGS_SIZE); | ||
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); | ||
|
||
s->link_state = OT_USBDEV_LINK_STATE_DISCONNECTED; |
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.
Could be part of the reset handler.
Everything is zero-initialized by QEMU
hw/opentitan/usbdev/ot_usbdev.c
Outdated
s->vbus_mode = OT_USBDEV_VBUS_OVERRIDE; | ||
} | ||
else { | ||
error_setg(errp, "%s: %s: invalid VBUS mode: %s", __func__, s->ot_id, s->vbus_mode_str); |
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.
Nit pick: Prefer &error_fatal
vs errp
which defaults to error_abort
, which in turn leaves the terminal is an awkward state as it is not properly restored when QEMU abruptly exits :-(
Signed-off-by: Douglas Reis <[email protected]> Signed-off-by: Amaury Pouly <[email protected]>
Replaces #164. This creates a minimal implementation of the usbdev block. Currently, the only thing supported are interrupts and also VBUS handling through a dedicated chardev channel. This allows on to pass the
usbdev_vbus_test
(after some opentitantool changes). Since the usbdev driver will be quite complicated, I think it's better to start small and build up. I also plan to make it multi-file so I created a directory for it.