usb: enable cpu boost for specific class drivers

add needs_cpu_boost field to usb_class_driver and manage boost state in
usb_core, similar to needs_exclusive_storage.

Change-Id: Ieb0cd7bedda5b24bb0d209d5ce907db30f4815db
This commit is contained in:
mojyack 2025-12-19 22:45:47 +09:00
parent 732f7bcfd9
commit bbdada7690
9 changed files with 23 additions and 9 deletions

View file

@ -266,23 +266,14 @@ static inline void usb_slave_mode(bool on)
if(on)
{
trigger_cpu_boost();
#ifdef HAVE_PRIORITY_SCHEDULING
thread_set_priority(thread_self(), PRIORITY_REALTIME);
#endif
disk_unmount_all();
}
else
{
#ifdef HAVE_PRIORITY_SCHEDULING
thread_set_priority(thread_self(), PRIORITY_SYSTEM);
#endif
/* Entered exclusive mode */
rc = disk_mount_all();
if(rc <= 0) /* no partition */
panicf("mount: %d",rc);
cancel_cpu_boost();
}
}

View file

@ -1497,6 +1497,7 @@ static bool usb_audio_fast_transfer_complete(int ep, int dir, int status, int le
struct usb_class_driver usb_cdrv_audio = {
.needs_exclusive_storage = false,
.needs_cpu_boost = false,
.config = 1,
.ep_allocs_size = ARRAYLEN(ep_allocs),
.ep_allocs = ep_allocs,

View file

@ -65,6 +65,7 @@ static int usb_charging_only_get_config_descriptor(unsigned char *dest,int max_p
struct usb_class_driver usb_cdrv_charging_only = {
.needs_exclusive_storage = false,
.needs_cpu_boost = false,
.config = 1,
.set_first_interface = usb_charging_only_set_first_interface,
.get_config_descriptor = usb_charging_only_get_config_descriptor,

View file

@ -54,6 +54,9 @@ struct usb_class_driver {
/* Set this to true if the driver needs exclusive disk access (e.g. usb storage) */
bool needs_exclusive_storage;
/* Set this to true if the driver needs to enable cpu boost */
bool needs_cpu_boost;
/* USB config number this driver belongs to */
uint8_t config;

View file

@ -823,6 +823,11 @@ static void usb_core_do_set_addr(uint8_t address)
usb_state = ADDRESS;
}
#if !defined(HAVE_PRIORITY_SCHEDULING)
#define thread_set_priority(...)
#define thread_get_priority(...)
#endif /* HAVE_PRIORITY_SCHEDULING */
static int usb_core_do_set_config(uint8_t new_config)
{
logf("usb_core: SET_CONFIG %d to %d", usb_config, new_config);
@ -852,6 +857,7 @@ static int usb_core_do_set_config(uint8_t new_config)
usb_state = usb_config == 0 ? ADDRESS : CONFIGURED;
bool require_exclusive = false;
bool require_cpu_boost = false;
/* activate new config */
if(usb_config != 0) {
@ -865,6 +871,7 @@ static int usb_core_do_set_config(uint8_t new_config)
continue;
}
require_exclusive |= drivers[i]->needs_exclusive_storage;
require_cpu_boost |= drivers[i]->needs_cpu_boost;
}
}
@ -876,6 +883,13 @@ static int usb_core_do_set_config(uint8_t new_config)
} else {
usb_release_exclusive_storage();
}
if(require_cpu_boost) {
trigger_cpu_boost();
thread_set_priority(thread_self(), PRIORITY_REALTIME);
} else {
thread_set_priority(thread_self(), PRIORITY_SYSTEM);
cancel_cpu_boost();
}
#ifdef HAVE_USB_CHARGING_ENABLE
usb_charging_maxcurrent_change(usb_charging_maxcurrent());

View file

@ -832,6 +832,7 @@ void usb_hid_send(usage_page_t usage_page, int id)
struct usb_class_driver usb_cdrv_hid = {
.needs_exclusive_storage = false,
.needs_cpu_boost = false,
.config = 1,
.ep_allocs_size = ARRAYLEN(ep_allocs),
.ep_allocs = ep_allocs,

View file

@ -692,6 +692,7 @@ static void usb_iap_notify_event(intptr_t data) {
struct usb_class_driver usb_cdrv_iap = {
.needs_exclusive_storage = false,
.needs_cpu_boost = true,
.config = 2,
.ep_allocs_size = ARRAYLEN(usb_iap_ep_allocs),
.ep_allocs = usb_iap_ep_allocs,

View file

@ -445,6 +445,7 @@ static void usb_serial_transfer_complete(int ep,int dir, int status, int length)
struct usb_class_driver usb_cdrv_serial = {
.needs_exclusive_storage = false,
.needs_cpu_boost = false,
.config = 1,
.ep_allocs_size = ARRAYLEN(ep_allocs),
.ep_allocs = ep_allocs,

View file

@ -1483,6 +1483,7 @@ static void fill_inquiry(IF_MD_NONVOID(int lun))
struct usb_class_driver usb_cdrv_storage = {
.needs_exclusive_storage = true,
.needs_cpu_boost = true,
.config = 1,
.ep_allocs_size = ARRAYLEN(ep_allocs),
.ep_allocs = ep_allocs,