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
(cherry picked from commit f363704a92fd7611cf01c8b3bcaf6e8913255207)
This commit is contained in:
Ray Chi 2022-03-01 21:57:03 +08:00
parent bc34b8944f
commit 49a9b9f3dd
2 changed files with 65 additions and 3 deletions

View file

@ -33,13 +33,55 @@ namespace gadget {
namespace V1_2 { namespace V1_2 {
namespace implementation { namespace implementation {
UsbGadget::UsbGadget() { UsbGadget::UsbGadget() : mGadgetIrqPath("") {
if (access(OS_DESC_PATH, R_OK) != 0) { if (access(OS_DESC_PATH, R_OK) != 0) {
ALOGE("configfs setup not done yet"); ALOGE("configfs setup not done yet");
abort(); 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) { void currentFunctionsAppliedCallback(bool functionsApplied, void *payload) {
UsbGadget *gadget = (UsbGadget *)payload; UsbGadget *gadget = (UsbGadget *)payload;
gadget->mCurrentUsbFunctionsApplied = functionsApplied; gadget->mCurrentUsbFunctionsApplied = functionsApplied;
@ -346,6 +388,10 @@ Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
mCurrentUsbFunctions = functions; mCurrentUsbFunctions = functions;
mCurrentUsbFunctionsApplied = false; mCurrentUsbFunctionsApplied = false;
// Get the gadget IRQ number before tearDownGadget()
if (mGadgetIrqPath.empty())
getUsbGadgetIrqPath();
// Unlink the gadget and stop the monitor if running. // Unlink the gadget and stop the monitor if running.
V1_0::Status status = tearDownGadget(); V1_0::Status status = tearDownGadget();
if (status != Status::SUCCESS) { if (status != Status::SUCCESS) {
@ -378,9 +424,15 @@ Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
} }
if (functions & GadgetFunction::NCM) { 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 { } 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"); ALOGI("Usb Gadget setcurrent functions called successfully");

View file

@ -19,6 +19,7 @@
#include <android-base/file.h> #include <android-base/file.h>
#include <android-base/properties.h> #include <android-base/properties.h>
#include <android-base/unique_fd.h> #include <android-base/unique_fd.h>
#include <android-base/parseint.h>
#include <android-base/strings.h> #include <android-base/strings.h>
#include <android/hardware/usb/gadget/1.2/IUsbGadget.h> #include <android/hardware/usb/gadget/1.2/IUsbGadget.h>
#include <android/hardware/usb/gadget/1.2/types.h> #include <android/hardware/usb/gadget/1.2/types.h>
@ -44,6 +45,7 @@ namespace implementation {
using ::android::sp; using ::android::sp;
using ::android::base::GetProperty; using ::android::base::GetProperty;
using ::android::base::SetProperty; using ::android::base::SetProperty;
using ::android::base::ParseUint;
using ::android::base::unique_fd; using ::android::base::unique_fd;
using ::android::base::ReadFileToString; using ::android::base::ReadFileToString;
using ::android::base::Trim; using ::android::base::Trim;
@ -71,6 +73,9 @@ using ::android::hardware::usb::gadget::V1_2::GadgetFunction;
using ::std::string; using ::std::string;
constexpr char kGadgetName[] = "11110000.dwc3"; constexpr char kGadgetName[] = "11110000.dwc3";
constexpr char kProcInterruptsPath[] = "/proc/interrupts";
constexpr char kProcIrqPath[] = "/proc/irq/";
constexpr char kSmpAffinityList[] = "/smp_affinity_list";
#ifndef UDC_PATH #ifndef UDC_PATH
#define UDC_PATH "/sys/class/udc/11110000.dwc3/" #define UDC_PATH "/sys/class/udc/11110000.dwc3/"
#endif #endif
@ -78,11 +83,15 @@ static MonitorFfs monitorFfs(kGadgetName);
#define SPEED_PATH UDC_PATH "current_speed" #define SPEED_PATH UDC_PATH "current_speed"
#define BIG_CORE "6"
#define MEDIUM_CORE "4"
struct UsbGadget : public IUsbGadget { struct UsbGadget : public IUsbGadget {
UsbGadget(); UsbGadget();
// Makes sure that only one request is processed at a time. // Makes sure that only one request is processed at a time.
std::mutex mLockSetCurrentFunction; std::mutex mLockSetCurrentFunction;
std::string mGadgetIrqPath;
uint64_t mCurrentUsbFunctions; uint64_t mCurrentUsbFunctions;
bool mCurrentUsbFunctionsApplied; bool mCurrentUsbFunctionsApplied;
UsbSpeed mUsbSpeed; UsbSpeed mUsbSpeed;
@ -99,6 +108,7 @@ struct UsbGadget : public IUsbGadget {
private: private:
Status tearDownGadget(); Status tearDownGadget();
Status getUsbGadgetIrqPath();
Status setupFunctions(uint64_t functions, const sp<V1_0::IUsbGadgetCallback> &callback, Status setupFunctions(uint64_t functions, const sp<V1_0::IUsbGadgetCallback> &callback,
uint64_t timeout); uint64_t timeout);
}; };