summaryrefslogtreecommitdiff
path: root/usb/gadget/UsbGadget.cpp
diff options
context:
space:
mode:
authorRay Chi <raychi@google.com>2022-03-01 21:57:03 +0800
committerTreeHugger Robot <treehugger-gerrit@google.com>2022-03-07 07:45:50 +0000
commitf363704a92fd7611cf01c8b3bcaf6e8913255207 (patch)
treea077255e92f346fa0a5767c216a9c1a30421bca0 /usb/gadget/UsbGadget.cpp
parentb30924e3599f2e92aeae498a6ae15d3b9a397930 (diff)
downloadgs201-f363704a92fd7611cf01c8b3bcaf6e8913255207.tar.gz
tune usb irq (dwc3) in usb gadget hal
Since affinity permission is changed from root to system, original permission change by script can't be used. Therefore, this patch will move the functionality to usb gadget hal. Bug: 220996010 Test: dwc3 irq could be located in medium/big cores after USB function switch Change-Id: Id993db9fc303e85a9a6337a0e41b1dfd6fc9a86a
Diffstat (limited to 'usb/gadget/UsbGadget.cpp')
-rw-r--r--usb/gadget/UsbGadget.cpp58
1 files changed, 55 insertions, 3 deletions
diff --git a/usb/gadget/UsbGadget.cpp b/usb/gadget/UsbGadget.cpp
index 23e5659..9fdf2ac 100644
--- a/usb/gadget/UsbGadget.cpp
+++ b/usb/gadget/UsbGadget.cpp
@@ -33,13 +33,55 @@ namespace gadget {
namespace V1_2 {
namespace implementation {
-UsbGadget::UsbGadget() {
+UsbGadget::UsbGadget() : mGadgetIrqPath("") {
if (access(OS_DESC_PATH, R_OK) != 0) {
ALOGE("configfs setup not done yet");
abort();
}
}
+V1_0::Status UsbGadget::getUsbGadgetIrqPath() {
+ std::string irqs;
+ size_t read_pos = 0;
+ size_t found_pos = 0;
+
+ if (!ReadFileToString(kProcInterruptsPath, &irqs)) {
+ ALOGE("cannot read all interrupts");
+ return Status::ERROR;
+ }
+
+ while (true) {
+ found_pos = irqs.find_first_of("\n", read_pos);
+ if (found_pos == std::string::npos) {
+ ALOGI("the string of all interrupts is unexpected");
+ return Status::ERROR;
+ }
+
+ std::string single_irq = irqs.substr(read_pos, found_pos - read_pos);
+
+ if (single_irq.find("dwc3", 0) != std::string::npos) {
+ unsigned int dwc3_irq_number;
+ size_t dwc3_pos = single_irq.find_first_of(":");
+ if (!ParseUint(single_irq.substr(0, dwc3_pos), &dwc3_irq_number)) {
+ ALOGI("unknown IRQ strings");
+ return Status::ERROR;
+ }
+
+ mGadgetIrqPath = kProcIrqPath + single_irq.substr(0, dwc3_pos) + kSmpAffinityList;
+ break;
+ }
+
+ if (found_pos == irqs.npos) {
+ ALOGI("USB gadget doesn't start");
+ return Status::ERROR;
+ }
+
+ read_pos = found_pos + 1;
+ }
+
+ return Status::SUCCESS;
+}
+
void currentFunctionsAppliedCallback(bool functionsApplied, void *payload) {
UsbGadget *gadget = (UsbGadget *)payload;
gadget->mCurrentUsbFunctionsApplied = functionsApplied;
@@ -359,6 +401,10 @@ Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
mCurrentUsbFunctions = functions;
mCurrentUsbFunctionsApplied = false;
+ // Get the gadget IRQ number before tearDownGadget()
+ if (mGadgetIrqPath.empty())
+ getUsbGadgetIrqPath();
+
// Unlink the gadget and stop the monitor if running.
V1_0::Status status = tearDownGadget();
if (status != Status::SUCCESS) {
@@ -391,9 +437,15 @@ Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
}
if (functions & GadgetFunction::NCM) {
- SetProperty("vendor.usb.dwc3_irq", "big");
+ if (!mGadgetIrqPath.empty()) {
+ if (!WriteStringToFile(BIG_CORE, mGadgetIrqPath))
+ ALOGI("Cannot move gadget IRQ to big core, path:%s", mGadgetIrqPath.c_str());
+ }
} else {
- SetProperty("vendor.usb.dwc3_irq", "medium");
+ if (!mGadgetIrqPath.empty()) {
+ if (!WriteStringToFile(MEDIUM_CORE, mGadgetIrqPath))
+ ALOGI("Cannot move gadget IRQ to medium core, path:%s", mGadgetIrqPath.c_str());
+ }
}
ALOGI("Usb Gadget setcurrent functions called successfully");