A cross-platform USB bridge port management method and module
By using a cross-platform USB bridge port management module, the system automatically identifies the platform type and generates an appropriate register access sequence, solving the problems of high development cost and high risk of timing conflicts in existing cross-platform USB port management technologies, and achieving unified management and simplified operation across platforms.
Patent Information
- Application Number
- CN202611676106.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-28
- Publication Date
- 2026-11-24
AI Technical Summary
Existing USB port management solutions lack a unified cross-platform adaptation method, resulting in high development costs and a high risk of timing conflicts. In particular, the management of USB 2.0 and USB 3.0 ports on different hardware platforms is cumbersome and prone to omissions.
A cross-platform USB bridge port management method and module is provided. It is encapsulated into a unified interface layer through an interface layer, a platform identification submodule, a PCIe indirect access submodule, and a platform execution submodule. It automatically identifies the platform type and generates an appropriate register access sequence to achieve unified management across platforms.
It reduces development costs and timing conflict risks, achieves unified management of cross-platform USB ports, simplifies underlying hardware operations, and reduces developers' need for register-level development on different platforms.
Smart Images

Figure CN123157644A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of interface management technology, and more specifically, to a cross-platform USB bridge port management method and module. Background Technology
[0002] With the increasing urgency of information security requirements, fine-grained management of USB (Universal Serial Bus) ports has become a crucial component of system security compliance in applications such as servers, workstations, and embedded systems. Unauthorized USB device access can lead to security risks such as data leaks and malicious code injection. In mainstream systems, USB controllers are typically integrated as PCIe (Peripheral Component Interconnect Express) devices. Host-side software can access the internal registers of the USB bridge chip indirectly through the PCIe configuration space, thereby achieving port management. The BIOS (Basic Input / Output System) firmware layer is the ideal level for implementing this management mechanism, as it can load and take effect earlier than the operating system drivers, offering high security.
[0003] In existing technologies, USB port management solutions primarily achieve device blacklist / whitelist management by loading specific drivers or applications at the operating system level, or by providing simple options to enable / disable all ports at the BIOS level. Some solutions achieve port control by directly reading and writing xHCI registers, but these are typically designed for a single hardware platform. When it comes to the independent management of USB 2.0 and USB 3.0 ports, existing solutions often adopt a separate handling strategy, lacking a unified interface encapsulation.
[0004] Existing USB port management solutions lack a systematic approach for fine-grained control of USB ports at the BIOS firmware level, particularly lacking a unified adaptation solution for different hardware platforms. Secondly, two typical platforms exist in actual products: one platform stores control registers in off-chip Flash, with write constraints allowing only 1s to be written to 0s, requiring block erasure for enable operations, rendering ordinary register procedures inapplicable; the other platform has scattered USB 2.0 register addresses and shared register bit fields for USB 3.0, and disabling requires powering off the port using PORTSC, making the operation cumbersome and prone to oversight. These two platforms differ significantly, making direct register-level development on the customer side costly, and existing solutions lack clear specifications for the timing of BIOS-based port management calls, posing a risk of timing conflicts. Summary of the Invention
[0005] The purpose of this application is to provide a cross-platform USB bridge chip port management method and module to solve the problems of high development cost and high timing conflict risk of existing USB port management schemes.
[0006] To achieve the above objectives, the technical solutions adopted in the embodiments of this application are as follows: On one hand, this application provides a cross-platform USB bridge chip port management method, applied to a cross-platform USB bridge chip port management module. The cross-platform USB bridge chip port management module includes an interface layer, a platform identification submodule, a PCIe indirect access submodule, a first type of platform execution submodule, and a second type of platform execution submodule. The cross-platform USB bridge chip port management method includes: The interface layer receives a call request, which includes the target port's port type parameter, port index parameter, and operation type parameter. The platform identification submodule detects the current hardware platform category, which includes a first type of platform and a second type of platform; and the USB port control register of the first type of platform is stored in the off-chip Flash address field, while the USB port control register of the second type of platform is a normal read / write register without Flash restrictions.
[0007] The target address of the internal target register of the USB bridge chip is determined based on the port type parameter and the port index parameter. When identified as the first type of platform, the first type of platform execution submodule is invoked, and a register access sequence conforming to the physical characteristics of the first type of platform is generated according to the operation type parameter for the target address in the port control register stored in the off-chip Flash address field. When identified as the second type of platform, the second type of platform execution submodule is invoked. Based on the operation type parameter, the enable control bit of the target address in the port control register is selected, and combined with the port power control bit, a register access sequence containing multi-register linkage control is generated. The PCIe indirect access submodule performs indirect addressing read and write operations on the target address through the PCIe configuration space register according to the register access sequence, so as to enable or disable the target port.
[0008] Optionally, the step of generating a register access sequence conforming to the physical characteristics of the first type of platform for the target address stored in the port control register in the off-chip Flash address field includes: Before performing a write operation on the off-chip Flash address field, a Flash write protection release operation is performed; When it is necessary to change the target bit from 0 to 1, a block erase operation is performed on the off-chip Flash before the write operation is executed; wherein, writing the target bit to 1 represents port enable, and writing the target bit to 0 represents port disable. After the write operation is completed, a Flash write protection recovery operation is performed.
[0009] Optionally, the step of the PCIe indirect access submodule performing indirect addressing read / write operations on the target address through the PCIe configuration space register according to the register access sequence includes: When the port control register is disabled, after the Flash write protection is released, the target bit of the target register is changed from 1 to 0 through the PCIe configuration space register, while the remaining bits remain 1; after the write is completed, the Flash write protection is restored. When the port control register is enabled, after the Flash write protection is released, all current values of the target register and associated register are read and recorded; after the block erase operation is performed on the off-chip Flash, all bits except the target bit in the target register and associated register are restored, and the target bit is written to 1; after the writing is completed, the Flash write protection is restored.
[0010] Optionally, the port type includes USB 2.0 and USB 3.0, and the step of generating a register access sequence that conforms to the physical characteristics of the first type of platform includes: When the port type is USB 2.0 and a disable operation is performed: Execute the Flash write protection unlock operation; clear the corresponding bit in the first port control register according to the port index; execute the Flash write protection restore operation; When the port type is USB 2.0 and an enable operation is performed: Execute the Flash write protection unlock operation; read and record the current values of the first port control register and the second port control register; execute the Flash block erase operation; restore the second port control register to the recorded value, set the corresponding bit in the first port control register and restore the remaining bits to the recorded value; execute the Flash write protection restore operation; When the port type is USB 3.0 and a disable operation is performed: Execute the Flash write protection unlock operation; clear the corresponding bit in the second port control register according to the port index; execute the Flash write protection restore operation; When the port type is USB 3.0 and an enable operation is performed: Execute the Flash write protection unlock operation; read and record the current values of the first port control register and the second port control register; execute the Flash block erase operation; restore the first port control register to the recorded value, set the corresponding bits in the second port control register and restore the remaining bits to the recorded value; execute the Flash write protection restore operation; The first port control register is used to control the USB 2.0 port, and the second port control register is used to control the USB 3.0 port.
[0011] Optionally, the port type includes USB 2.0 and USB 3.0. When the operation type is disabled, the register access sequence generated by the second type of platform execution submodule includes: The power control position of the corresponding USB 2.0 port is set to the power-off state via the xHCI PORTSC register. The power control position of the corresponding USB 3.0 port is set to the power-off state via the xHCI PORTSC register. Write a disabled value to the target bit of the corresponding USB 2.0 port control register or USB 3.0 port control register.
[0012] Optionally, the register access sequence generated by the second type of platform execution submodule includes: When the port type is USB 2.0 and a disable operation is performed: power off the corresponding USB 2.0 port; power off the corresponding USB 3.0 port; set the enable control bit of the corresponding USB 2.0 independent port management register to 1; When the port type is USB 3.0 and a disable operation is performed: power off the corresponding USB 2.0 port; power off the corresponding USB 3.0 port; set the bit field corresponding to the port index in the USB 3.0 common port management register to 1.
[0013] Optionally, the PCIe configuration space of the USB bridge chip includes an address register, a data register, and an access control register; the step of the PCIe indirect access submodule performing indirect addressing read / write operations on the target address through the PCIe configuration space register according to the register access sequence includes: When performing a write operation, the target register address is written to the address register; the value to be written is written to the data register; a 1 is written to the write request initiation bit of the access control register to trigger the write transaction; the write request initiation bit of the access control register is polled until the write request initiation bit is automatically cleared to confirm that the write operation is complete. When performing a read operation, the target register address is written to the address register; a 1 is written to the read request initiation bit of the access control register to trigger a read transaction; the read request initiation bit of the access control register is polled until the read request initiation bit is automatically cleared; and the current value of the target register is read from the data register.
[0014] Optionally, the step of determining the target address of the internal target register of the USB bridge chip based on the port type parameter and the port index parameter includes: Obtain the PCIe base address of the USB bridge chip; Based on the port type parameter, determine the register group base offset corresponding to the port type; Calculate the index offset of the target port within the register group based on the port index parameter; The target address of the target register is the sum of the PCIe base address, the register set base offset, and the index offset; and the target address is written into the address register when performing a read or write operation.
[0015] Optionally, the cross-platform USB bridge port management module further includes a timing control submodule, and the method further includes: Before the PCIe indirect access submodule performs indirect addressing read / write operations, the timing control submodule confirms that the current system time is within the time window after the PCI bus enumeration is completed and before the xHCI driver is initialized; and inserts a predetermined delay between each step of the register access sequence executed by the first type of platform execution submodule.
[0016] On the other hand, this application also provides a cross-platform USB bridge port management module, which includes: The interface layer provides a unified application programming interface to the outside world, receives call requests containing port type, port index, and operation type, and returns the operation result; and the port type parameter and port index parameter are used to determine the target address of the internal target register of the USB bridge chip. The platform identification submodule is used to automatically detect the current hardware platform category during module initialization. The hardware platform category includes a first type platform and a second type platform. The USB port control register of the first type platform is stored in the off-chip Flash address field, while the USB port control register of the second type platform is a normal read / write register without Flash restrictions. The first type of platform execution submodule is used to generate a register access sequence that conforms to the physical characteristics of the first type of platform when the hardware platform category is the first type of platform, based on the operation type parameter and targeting the target address in the port control register stored in the off-chip Flash address field. The second type of platform execution submodule is used to generate a register access sequence containing multi-register linkage control based on the operation type parameter, the enable control bit of the target address in the port control register, and the port power control bit, when the hardware platform category is the second type of platform. The PCIe indirect access submodule is used to perform indirect addressing read and write operations on the target address through the PCIe configuration space register according to the register access sequence, so as to enable or disable the target port.
[0017] Compared with the prior art, this application has the following advantages: This application provides a cross-platform USB bridge chip port management method and module. The cross-platform USB bridge chip port management module includes an interface layer, a platform identification submodule, a PCIe indirect access submodule, a first-type platform execution submodule, and a second-type platform execution submodule. This application encapsulates the low-level hardware operations of USB port management into a unified interface layer, platform identification layer, policy execution layer, and indirect access layer. This allows upper-layer software to initiate calls only with port type, port index, and operation type as parameters. The module automatically identifies the platform category, generates an appropriate register access sequence, and completes read and write operations, thus avoiding the need for developers to perform register-level development for different platforms. Furthermore, the timing control submodule constrains the call timing to after PCI enumeration and before xHCI driver initialization, reducing development costs and timing conflict risks from an architectural perspective.
[0018] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0019] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 An exemplary flowchart of a cross-platform USB bridge port management method provided in this application embodiment.
[0021] Figure 2 A schematic diagram of the parameters of the interface layer provided in the embodiments of this application.
[0022] Figure 3 A schematic diagram of the parameters of the internal registers of the USB bridge chip provided in the embodiments of this application.
[0023] Figure 4 A schematic diagram of the parameters of the port control register provided in an embodiment of this application.
[0024] Figure 5 This is a schematic diagram of the parameters of the USB 2.0 port control register provided in an embodiment of this application.
[0025] Figure 6 This is a schematic diagram of the parameters of the USB 3.0 port control register provided in an embodiment of this application.
[0026] Figure 7 This is a schematic diagram of the parameters of the xHCI PORTSC register provided in an embodiment of this application. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0028] Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0029] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0030] It should be noted that in this paper, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0031] The following detailed description of some embodiments of this application is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0032] As described in the background section, in current mainstream systems, the USB controller (xHCI, or eXtensible Host Controller Interface) is typically integrated into the chipset or a separate bridge chip as a PCIe device. Host-side software (such as BIOS firmware or UEFI firmware) can access the internal controller registers of the USB bridge chip indirectly by reading and writing the PCIe configuration space registers, thereby achieving low-level control over the USB host controller and its ports.
[0033] However, in actual product adaptation, there are two typical hardware platforms with significant differences.
[0034] The first platform stores the USB port control register in an off-chip Flash memory domain. This Flash memory has specific write constraints: a write operation to a memory cell can only change a logic 1 to a logic 0; to change a logic 0 to a logic 1 (even to a disabled port), an erase operation must be performed on the entire Flash block. Furthermore, write protection must be disabled before normal read / write operations and re-enabled afterward. This Flash memory characteristic makes ordinary register read / write procedures unsuitable; simply writing in the conventional register manner will result in enable operation failure.
[0035] The second platform uses ordinary read / write registers for its USB port control registers, without Flash storage constraints. However, the USB 2.0 and USB 3.0 register layouts differ: in USB 2.0, each port's control register address is independent and distributed, with each port occupying its own independent register address space; while in USB 3.0, four ports share different bit fields of a single register. Furthermore, disabling the port on this platform requires using the PortPower (PP) bit of the xHCI PORTSC (Port Status and Control) register to power off the port. If only the control register is configured while ignoring the power-off step, the disabling operation will not take effect. The operation is cumbersome and prone to omissions.
[0036] Existing USB port management solutions have the following shortcomings: 1. There is a lack of systematic methods for fine-grained management of USB ports at the BIOS firmware level, especially a unified adaptation solution for different hardware platforms. In existing technologies, USB device management usually relies on operating system-level drivers or applications rather than being completed at the firmware level, which leads to the risk of user-space software being bypassed.
[0037] 2. The port control register of the first platform has Flash storage characteristics, and the ordinary register read and write process cannot meet the requirements. The ordinary solution fails to recognize the Flash write constraint (only 1 can be written to 0, and 0 to 1 requires block erasure), which leads to the failure of the enable operation or erroneous operation affecting the configuration status of adjacent ports.
[0038] 3. In the second platform, the addresses of the USB 2.0 port registers are independent and scattered, while the USB 3.0 ports share different bit fields of a single register. Furthermore, disabling the port requires using the PortPower field of the PORTSC register to turn off the port power. The operation is cumbersome, and if developers do not fully execute all the steps, it can easily lead to disabling failure or abnormal port status.
[0039] 4. The two platforms differ significantly. If customers directly perform register-level development, they need to be familiar with the register specifications, timing requirements, and operational constraints of each platform, resulting in high development and maintenance costs and a high risk of introducing compatibility defects. Maintaining independent code branches for different platforms is also detrimental to large-scale product delivery.
[0040] 5. Existing solutions lack clear specifications regarding the timing of USB port management under BIOS. If executed before the PCI driver enumeration is complete, the PCIe configuration space of the USB bridge chip has not yet been initialized, and indirect addressing cannot be completed; if executed after the xHCI driver initialization, the xHCI driver may have already restored the port to its default state, causing the management configuration to be overwritten and ineffective, resulting in a significant risk of timing conflicts.
[0041] In view of this, this application provides a cross-platform USB bridge chip port management method, which encapsulates the low-level operations required for USB bridge chip port management into a standardized module and exposes a unified application programming interface (API). The client-side BIOS firmware or upper-level software only needs to call the interface provided by the module, without having to pay attention to the differences in the underlying platform and register details, to independently enable and disable USB 2.0 and USB 3.0 ports.
[0042] The following provides an exemplary description of the cross-platform USB bridge port management method provided in this application. For one implementation method, please refer to [link / reference]. Figure 1 The method includes: S102, the interface layer receives the call request, which includes the port type parameter, port index parameter, and operation type parameter of the target port.
[0043] S104, the platform identification submodule detects the current hardware platform category, which includes the first type of platform and the second type of platform; and the USB port control register of the first type of platform is stored in the off-chip Flash address field, while the USB port control register of the second type of platform is a normal read and write register without Flash restrictions.
[0044] S106 determines the target address of the internal target register of the USB bridge chip based on the port type parameter and the port index parameter.
[0045] S108, when identified as a first-class platform, calls the first-class platform execution submodule, and generates a register access sequence that conforms to the physical characteristics of the first-class platform based on the operation type parameter and the target address in the port control register stored in the off-chip Flash address field.
[0046] S110, when identified as a second type platform, calls the second type platform execution submodule, and generates a register access sequence containing multi-register linkage control based on the operation type parameter, the enable control bit of the target address in the port control register, and the port power control bit.
[0047] S112, the PCIe indirect access submodule performs indirect addressing read and write operations on the target address through the PCIe configuration space register according to the register access sequence, so as to enable or disable the target port.
[0048] It should be noted that a USB bridge chip refers to an xHCI controller chip integrated into the system or a chipset module containing xHCI controller functionality. This USB bridge chip exists in the system as a PCIe device, with its own PCIe configuration space and PCIe base address register. During PCIe bus enumeration, the system BIOS allocates an MMIO address space for this USB bridge chip and writes the allocated base address into the bridge chip's BAR register. The USB bridge chip internally contains multiple port management registers, which are used to control the enabling, disabling, reset, and power management of each USB port.
[0049] The PCIe configuration space is a standard register space defined in the PCIe specification. Each PCIe device contains a 256-byte standardized header area and several device-related extension areas within its configuration space. System software can access this configuration space via the PCIe bus protocol, and it remains accessible even before the device BAR is allocated. In this application, the PCIe indirect access submodule utilizes the accessibility of the configuration space in the early stages of device enumeration to achieve indirect access to the internal registers of the USB bridge chip through a specific register window within the configuration space.
[0050] Furthermore, it is understood that the cross-platform USB bridge port management module provided in this application, as a firmware software module, can be integrated into the BIOS or UEFI firmware of a computer system. This module is burned into the SPI Flash on the motherboard along with the BIOS firmware during the firmware build phase. After the system powers on, the CPU loads and executes the module's code from the BIOS firmware, and the module begins operation.
[0051] Furthermore, the internal architecture of this cross-platform USB bridge port management module is logically divided into at least five sub-modules: an interface layer, a platform identification sub-module, a PCIe indirect access sub-module, a first-type platform execution sub-module, and a second-type platform execution sub-module. In addition, in one implementation, the module also includes a timing control sub-module, used to constrain and manage the timing of module calls and operation sequences. The sub-modules interact through function calls and data structure transfers, forming a complete management chain from user requests to the underlying hardware.
[0052] The interface layer provides a unified API (Application Programming Interface). For example, it can provide a set of application programming interfaces in the form of standard C language functions. These interfaces include port disable interface, port enable interface, port status query interface, etc. The interface parameters include port type (USB2.0 / USB 3.0), port index (PORT1~PORT4) and operation type (enable / disable).
[0053] For example, the parameters of the interface layer are as follows: Figure 2 As shown, based on this, when the client side makes a call, its pseudocode can be UsbPortDisable(USB_2_0, PORT1); UsbPortEnable(USB_3_0, PORT2). When the client side calls the above interfaces, it does not need to know the details of the underlying register addresses, Flash constraints, PORTSC coordination, etc., as the module automatically completes all the underlying operations.
[0054] Furthermore, after receiving a call request containing the target port's port type parameter, port index parameter, and operation type parameter, the interface layer first performs a validity check on the call parameters. For example, it checks whether the port type parameter is a valid value for USB 2.0 or USB 3.0, whether the port index parameter is within the range of ports supported by the module, and whether the operation type parameter is a valid value for enabling or disabling. If the parameter validation fails, the interface layer immediately returns the corresponding error code and stops execution. If the parameter validation passes, the interface layer packages these parameters into an internal data structure and passes it to subsequent submodules for processing.
[0055] It's worth noting that by setting up the interface layer, client-side calls become much more convenient. The client simply needs to call the port enable or disable interface, passing in the port type and port index, to complete the operation. For example, in the BIOS's USB security policy configuration module, the system administrator can call the UsbPortDisable function and pass in the USB2 and PORT1 parameters to disable the motherboard's first USB 2.0 port. Alternatively, in the system security initialization process, the UsbPortEnable function can be called and the USB3 and PORT2 parameters passed in to enable the motherboard's second USB 3.0 port. The client doesn't need to worry about the location of the port control register, whether Flash write protection needs to be disabled, or whether the PORTSC power needs to be turned off simultaneously—all these low-level details are handled automatically by the module.
[0056] The platform identification submodule is executed once during the module initialization phase. Its main function is to automatically detect the type of hardware platform currently in operation during the module initialization phase and bind the correct underlying execution strategy for subsequent port management operations, thereby masking platform differences.
[0057] For example, the specific detection mechanism of the platform identification submodule can be as follows: By scanning the PCIe bus, the identification codes of the USB bridge chip in the PCIe configuration space are obtained, namely the Vendor ID and Device ID. These two identifiers are unique codes assigned by the PCIe device manufacturer to each device model. The module has a pre-built platform feature table, which records the correspondence between the Vendor ID and Device ID of known hardware platforms and the platform category. The platform identification submodule compares the read Vendor ID and Device ID with the feature table and routes the data to the corresponding execution submodule based on the comparison result. If a record of the first type of platform is matched, the global function pointer is bound to the entry function of the execution submodule of the first type of platform; if a record of the second type of platform is matched, the global function pointer is bound to the entry function of the execution submodule of the second type of platform. If no known platform is matched, the module returns an error message indicating that the platform is not supported and terminates initialization.
[0058] In one implementation, when the platform identification submodule identifies the current hardware platform as a Class 1 platform, all subsequent port control operations will call the functions of the Class 1 platform execution submodule. This submodule designs a complete operation sequence for the port control registers of off-chip Flash storage, including steps such as write protection removal, conditional erase, atomic write, and write protection recovery. When the platform identification submodule identifies a Class 2 platform, all subsequent port control operations will call the functions of the Class 2 platform execution submodule. This submodule, taking into account the characteristics of ordinary readable and writable registers, designs USB 2.0 independent register operation procedures and USB 3.0 shared register bit field operation procedures, and includes PORTSC power control linkage logic in the disable operation.
[0059] The PCIe indirect access submodule is the lowest-level hardware access component in the module, encapsulating all read and write operations to the internal registers of the USB bridge chip. Within the USB bridge's PCIe configuration space, three registers are pre-configured for indirect access: the address register, the data register, and the access control register. The specific offset addresses of these three registers are determined by the USB bridge's hardware design; different bridge models may use different offset values. The PCIe indirect access submodule uniformly implements read and write operations to the USB bridge's internal registers through the following three PCIe configuration space registers: the actual register address = the base address of the configuration space allocated by the host for this PCIe device + the offset address. Based on this, such as... Figure 3 As shown, the address register stores the address of the target register to be accessed. When it is necessary to read or write a control register inside the USB bridge chip, the complete physical address of the control register must first be written to this address register. This address register is typically 32 bits wide and supports addressing any register within a 4GB address space. The data register stores data to be written or read. During a write operation, the software places the data to be written into the data register; during a read operation, the hardware stores the read data into the data register for the software to access. The access control register contains write request initiation bits and read request initiation bits. The software triggers the hardware to perform indirect access operations by setting the corresponding initiation bits.
[0060] As one implementation, the steps of the PCIe indirect access submodule performing indirect addressing read / write operations on the target address through the PCIe configuration space register according to the register access sequence include: When performing a write operation, the target register address is written to the address register; the value to be written is written to the data register; a 1 is written to the write request initiation bit of the access control register to trigger the write transaction; the write request initiation bit of the access control register is polled until the write request initiation bit is automatically cleared to confirm that the write operation is complete. When performing a read operation, the target register address is written to the address register; a 1 is written to the read request initiation bit of the access control register to trigger the read transaction; the read request initiation bit of the access control register is polled until it is automatically cleared; and the current value of the target register is read from the data register.
[0061] Furthermore, the steps for determining the target address of the internal target register of the USB bridge chip based on the port type parameter and the port index parameter include: Obtain the PCIe base address of the USB bridge chip; Determine the register set base offset corresponding to the port type based on the port type parameter; Calculate the index offset of the target port within the register group based on the port index parameter; The target address of the target register is the sum of the PCIe base address, the register set base offset, and the index offset; and the target address is written to the address register when performing a read or write operation.
[0062] As one implementation, when determining the USB target address, the bridge chip's PCIe base address is stored in the BAR register of the PCIe configuration space. During the PCIe bus enumeration process, the system BIOS allocates an MMIO address space for each PCIe device and writes the allocated base address into the device's BAR register. In the initialization phase, the module of this application can obtain the USB bridge chip's MMIO base address by reading the value of the BAR register through the PCIe configuration space. Once obtained, this base address can be reused in all subsequent indirect access operations without repeated reading.
[0063] The internal offset address of the target register is determined by both the port type parameter and the port index parameter. This application uses an address offset mapping method to calculate the target address. Specifically, the register set base offset corresponding to the port type is first determined based on the port type parameter. In a specific embodiment of this application, the register set base offset of the USB 2.0 port control register is 0x00000100, and the register set base offset of the USB 3.0 port control register is 0x00000200. These offset values are relative to the MMIO base address of the USB bridge chip.
[0064] Secondly, the index offset of the target port within the register group is calculated based on the port index parameters. In one specific embodiment of this application, the address space occupied by the register of each port is 0x00000010 bytes, therefore the index offset is equal to the port index value multiplied by 0x00000010. For example, the index offset of port 1 is 0x00000000, the index offset of port 2 is 0x00000010, the index offset of port 3 is 0x00000020, and the index offset of port 4 is 0x00000030.
[0065] The complete physical address of the target register is equal to the sum of the PCIe base address, the register set base offset, and the index offset. Taking a PCIe base address of 0xFE000000, a port type of USB 2.0, and a port index of 1 as an example, the target address is equal to 0xFE000000 plus 0x00000100 plus 0x00000000, which equals 0xFE000100. This address is the complete physical address of the target port control register and will be filled into the address register of the PCIe indirect access submodule.
[0066] The address calculation method described above enables the module of this application to accurately locate the control register corresponding to any port of any port type through simple numerical calculations, without needing to store a fixed address value for each port, thus reducing the module's storage overhead and improving code maintainability. When the number of ports expands, only the calculation step size of the index offset needs to be adjusted accordingly, without modifying a large number of hard-coded addresses.
[0067] In another implementation, the address offset calculation can be performed by a module at a higher level than the platform execution submodule, such as the interface layer. In this implementation, after receiving a call request, the interface layer directly calculates the target address based on the port type and port index parameters, and then passes the target address as a parameter to the platform execution submodule. The platform execution submodule focuses on generating operation strategies for the specific platform and is no longer responsible for address calculation. The advantage of this division of responsibilities is that it centralizes the address calculation logic at a higher layer, facilitating unified management and maintenance. However, the disadvantage is that it increases the coupling between the interface layer and the execution submodule. Both approaches have their advantages and disadvantages. This application does not limit the specific execution level of the address calculation; those skilled in the art can flexibly choose according to the actual module architecture design requirements.
[0068] In this application, when the PCIe indirect access submodule performs a write operation, it first fills the target register address into the address register (address offset D10h), which is obtained by adding the PCIe base address to the internal offset of the target register. Next, it fills the data register (address offset D14h) with the value to be written. Then, it writes a logic 1 to the write request initiation bit of the access control register (offset D18h), triggering the bus controller inside the USB bridge to initiate a write transaction. Upon detecting that the write request initiation bit is set, the hardware logic inside the USB bridge automatically reads the target address from the address register, reads the value to be written from the data register, and then writes the data to the target register via the internal bus. After the write operation is complete, the hardware logic automatically clears the write request initiation bit. The software can confirm that the write operation is complete by polling this bit and waiting for it to automatically clear.
[0069] When the PCIe indirect access submodule performs a read operation, it first fills the target register address into the address register (offset D10h). Next, it writes a logic 1 to the read request initiation bit in the access control register (offset D18h). This operation triggers the bus controller inside the USB bridge to initiate a read transaction. Upon detecting that the read request initiation bit is set, the hardware logic inside the USB bridge automatically reads the target address from the address register, reads data from the target register via the internal bus, and stores the read data in the data register. After the read operation is complete, the hardware logic automatically clears the read request initiation bit and updates the data register to the current value of the target register. The software polls the read request initiation bit, waiting for it to automatically clear, and then reads the current value of the target register from the data register (offset D14h).
[0070] Understandably, the PCIe indirect access submodule provided in this application has the following effects: First, this submodule acquires and saves the PCIe configuration space base address during the module initialization phase. All subsequent indirect access operations use this base address plus a fixed offset to access the three indirect access registers, eliminating the need for repeated PCIe bus scanning. Second, this submodule uses a polling-based approach to confirm operation completion, independent of interrupt mechanisms. Therefore, no interrupt handlers are required in the BIOS environment, simplifying the module's implementation complexity. Furthermore, this submodule completely shields the upper-level execution submodule from the timing details of indirect access. The upper-level submodule only needs to call a unified read / write interface function and pass in the address and data to complete the operation, without needing to concern itself with the specific offsets and operation order of the address register, data register, and access control register.
[0071] As one implementation method, the steps for generating a register access sequence that conforms to the physical characteristics of the first type of platform for the target address stored in the port control register in the off-chip Flash address domain include: Before performing a write operation on the off-chip Flash address field, perform a Flash write protection release operation.
[0072] When it is necessary to change the target bit from 0 to 1, a block erase operation is performed on the external Flash before the write operation is executed; where writing the target bit to 1 means the port is enabled, and writing the target bit to 0 means the port is disabled.
[0073] After the write operation is completed, a Flash write protection recovery operation is performed.
[0074] In the first type of platform, the basic storage unit of Flash memory is a floating-gate transistor, which represents the logic state by injecting or releasing charge in the floating gate. In typical NOR Flash, an erase operation sets the storage unit to a logic 1 state, and a programming operation sets it to a logic 0 state. Therefore, Flash memory cells exhibit asymmetry in write operations; writing a logic 1 to a logic 0 can be achieved through programming, but writing a logic 0 to a logic 1 requires first performing an erase operation to restore the entire block to an all-1 state. This physical characteristic means that when performing a write operation on the port control register in the Flash domain, a simple register assignment operation cannot be performed; the relationship between the current state of the target bit and the target state must be considered.
[0075] Based on this, the steps by which the PCIe indirect access submodule performs indirect addressing read / write operations on the target address through the PCIe configuration space register according to the register access sequence include: When the port control register is disabled, after the Flash write protection is released, the target bit of the target register is changed from 1 to 0 through the PCIe configuration space register, while the remaining bits remain 1; after the write is completed, the Flash write protection is restored.
[0076] When the port control register is enabled, after the Flash write protection is released, all current values of the target register and associated register are read and recorded; after the block erase operation is performed on the off-chip Flash, all bits except the target bit in the target register and associated register are restored, and the target bit is written to 1; after the writing is completed, the Flash write protection is restored.
[0077] The port control registers in the Flash domain include a first port control register and a second port control register. The first port control register controls the enable and disable status of the USB 2.0 port, and its bit width can be 32 bits. A logic 1 indicates that the corresponding USB 2.0 port is enabled, and a logic 0 indicates that the corresponding USB 2.0 port is disabled. The second port control register controls the enable and disable status of the USB 3.0 port, and its bit width can also be 32 bits. The correspondence between bit values and port status is the same as that of the first port control register. The parameters of the port control registers are as follows: Figure 4As shown. In addition to the port control register, the first platform also includes relevant registers for the Flash controller, used to control the write protection status and block erase operations of the Flash. The Flash controller provides a set of MMIO registers, including a first register, a second register, and a third register. The first register is the command control register of the Flash controller, used to receive different operation command sequences; the second register is the key or status register of the Flash controller, used to load the unlock key or query the operation status; the third register is the address register of the Flash controller, used to specify the starting address for block erase.
[0078] In the first platform, any write operation to the Flash domain must be performed with Flash write protection disabled. Flash write protection is a security feature provided by the Flash controller. When write protection is enabled, all write and erase operations to the Flash memory array are hardware-blocked, preventing firmware from accidentally writing to the Flash under abnormal conditions and causing the system to fail to boot. Therefore, the Flash write protection disabling sequence must be executed before performing port control operations.
[0079] The Flash write-protection unlock sequence includes: first, writing a first preset value to the first register of the Flash controller, which enables the key writing window. Next, writing a second preset value to the second register of the Flash controller, which loads the unlock key. Finally, writing a third preset value to the first register of the Flash controller, which triggers unlock confirmation. These three steps must be executed strictly in sequence, and a predetermined delay must be inserted between each step to ensure that the Flash controller's internal state machine can correctly complete each state transition.
[0080] As one implementation method, the cross-platform USB bridge port management module also includes a timing control submodule, and the method also includes: Before the PCIe indirect access submodule performs indirect addressing read / write operations, the timing control submodule confirms that the current system time is within the time window after the PCI bus enumeration is completed and before the xHCI driver initialization; and inserts a predetermined delay between each step of the register access sequence executed by the first type of platform execution submodule. For example, the predetermined delay can be 10 milliseconds.
[0081] After completing the port control operation, Flash write protection needs to be re-enabled to prevent accidental Flash writes during subsequent firmware processes. In one specific embodiment of this application, the Flash write protection recovery sequence includes the following steps: First, a first preset value is written to the first register of the Flash controller; this operation also enables the key writing window. Second, a fourth preset value is written to the second register of the Flash controller; this operation loads the write protection enable key. Third, a third preset value is written to the first register of the Flash controller; this operation triggers write protection enable confirmation. Similar to the deactivation sequence, a predetermined delay is also required between each step of the recovery sequence.
[0082] In one specific embodiment of this application, the first preset value is 0x06000001, the second preset value is 0x00000000, the third preset value is 0x01008001, and the fourth preset value is 0x0000007C. The addresses of the first register, the second register, and the third register are 0x40060090, 0x400600A8, and 0x40060094, respectively. Based on this, the Flash write protection is released by: first writing 0x06000001 to 0x40060090, then writing 0x0 to 0x400600A8, and finally writing 0x01008001 to 0x40060090. Enabling write protection for Flash involves writing 0x06000001 to 0x40060090, then writing 0x7C to 0x400600A8, and finally writing 0x01008001 to 0x40060090. Erasing Flash blocks involves writing 0x06000001 to 0x40060090, then writing 0x8000 to 0x40060094, and finally writing 0x200A0001 to 0x40060090.
[0083] When disabling a USB 2.0 port, since the target bit of the port control register is written from logic 1 to logic 0, this operation is a Flash programming operation and does not require block erasure. Therefore, the disabling process is relatively simple. First, the Flash write protection release sequence is executed, putting the Flash controller into a writable state. Second, the current value of the first port control register is read through the PCIe indirect access submodule, the bit corresponding to the target port is cleared to zero, and other bits remain unchanged. Then, the modified value is written back to the first port control register through the PCIe indirect access submodule. Finally, the Flash write protection recovery sequence is executed to relock the Flash, completing the disabling operation.
[0084] When enabling a USB 2.0 port, the enable operation requires writing the target bit from logic 0 to logic 1. However, Flash cannot write 0 to 1 without erasing. Therefore, the enable operation must include a block erase step. However, the granularity of a block erase operation is typically 64KB or larger, and the erase operation changes the entire contents of the Flash block to logic 1. If the first port control register and the second port control register are located in the same Flash block, erasing that block will erase the entire contents of both registers simultaneously. This may result in the loss of configuration for other ports, or even the complete loss of configuration for another type of port.
[0085] To address the aforementioned issues, this application designs a backup-and-recovery atomic write mechanism in the first type of platform execution submodule. Specifically, before performing the erase operation, the current values of all registers potentially affected by the erase are read and stored in memory. Then, a block erase is performed. Finally, after the erase is complete, all register values except the target bit are restored, and the target bit is set to the desired value.
[0086] Specifically, first, the Flash write-protection release sequence is executed, putting the Flash controller into a writable state. Second, the current values of the first and second port control registers are read via the PCIe indirect access submodule and stored in memory variables. Then, a Flash block erase operation is performed, erasing the entire Flash block containing the first and second port control registers to logic 1. After erasure, all bits in both registers become 1, meaning all ports are enabled. Next, data recovery is performed. For the second port control register, it is restored to its previously saved current value, ensuring the configuration of each USB 3.0 port remains unchanged after the erase operation. For the first port control register, the bit corresponding to the target port is written to 1 to enable it, while the other bits are restored to their previously saved current values, ensuring the configuration of other USB 2.0 ports remains unchanged after the erase operation. Finally, the Flash write-protection recovery sequence is executed to relock the Flash, completing the enabling operation.
[0087] In the above process, the corresponding bit of the target port in the first port control register is set to 1, enabling the operation. Meanwhile, the other bits of this register, as well as all bits of the second port control register, are restored to their values before erasure, thus ensuring that the block erase operation does not affect the control status of other ports. This backup-and-recovery operation overcomes the physical limitation that Flash cannot directly write 0 to 1, and also ensures the atomic consistency of port configurations, meaning that the erase operation will not destroy the configuration status of other ports.
[0088] The management process for USB 3.0 ports follows the same basic principle as that for USB 2.0 ports, but the operation target changes from the first port management register to the second port management register. When disabling a USB 3.0 port, the bit corresponding to the target port in the second port management register is cleared to zero via the PCIe indirect access submodule, while the remaining bits remain unchanged. When enabling a USB 3.0 port, a backup-and-recovery atomic write mechanism is also used. The current values of the first and second port management registers are read and saved, a Flash block erase is performed, and then all values of the first port management register are restored. Simultaneously, the bit corresponding to the target port in the second port management register is restored to its original value, while the other bits are also restored.
[0089] In all Flash operations on the first platform described above, delay control between steps is crucial. When the Flash controller performs operations such as write protection release, block erase, and write protection recovery, its internal state machine requires a certain amount of time to complete state transitions and physical operations. If the software starts executing the next operation before the Flash controller has completed the current operation, it may lead to operation failure or data corruption. Therefore, the timing control submodule in this application inserts a predetermined delay between each step of the Flash operation sequence. The specific duration of this delay is determined according to the specifications of the Flash chip, typically ranging from 5 milliseconds to 50 milliseconds. In a preferred embodiment, the delay is set to 10 milliseconds.
[0090] In practical applications, in the first platform, the steps to disable the USB 2.0 port include: executing the Flash unwrite protection sequence (with a 10ms delay between each step), writing 0 to the corresponding bit in the 0x08008000 register according to the target port index, keeping the remaining bits at 1, and executing the Flash unwrite protection sequence.
[0091] Taking disabling USB 2.0 port 1 as an example, the steps include: writing 0x06000001 to 0x40060090 (delay 10ms), writing 0x0 to 0x400600A8, writing 0x01008001 to 0x40060090 (delay 10ms), clearing bit0 of register 0x08008000, writing 1 to bits[3:1], writing 0x06000001 to 0x40060090 (delay 10ms), writing 0x7C to 0x400600A8, and writing 0x01008001 to 0x40060090.
[0092] The steps to enable a USB 2.0 port include: executing the Flash unwrite protection sequence, reading and recording the current values of 0x08008000 and 0x08008004, executing Flash block erase, and restoring all data of 0x08008004; for 0x08008000, writing 1 to the corresponding bit of the target port, restoring the recorded values of the remaining bits, and executing the Flash unwrite protection sequence.
[0093] The steps to disable a USB 3.0 port include: executing the Flash unwrite protection sequence, writing 0 to the corresponding bit in register 0x08008004 according to the target port index, keeping the remaining bits at 1, and executing the Flash write protection enable sequence.
[0094] The steps to enable a USB 3.0 port include: executing the Flash unwrite protection sequence, reading and recording the current values of 0x08008000 and 0x08008004, executing Flash block erase, and restoring all data of 0x08008000; for 0x08008004, writing 1 to the corresponding bit of the target port, restoring the recorded values of the remaining bits, and executing the Flash unwrite protection sequence.
[0095] As one implementation, the port types include USB 2.0 and USB 3.0. When the operation type is disabled, the register access sequence generated by the second type of platform execution submodule includes: The power control position of the corresponding USB 2.0 port is set to the power-off state via the xHCI PORTSC register.
[0096] The power control position of the corresponding USB 3.0 port is set to the power-off state via the xHCI PORTSC register.
[0097] Write a disabled value to the target bit of the corresponding USB 2.0 port control register or USB 3.0 port control register.
[0098] In the second platform, each USB 2.0 port has its own independent port control register, and each port control register corresponds to a physical port. Their addresses are consecutive and independent. For example... Figure 5 As shown, each USB 2.0 port control register has a bit width of 32 bits, where bit 31 is the port disable / enable bit. When this bit is logic 1, it indicates that the port is disabled, and when this bit is logic 0, it indicates that the port is enabled.
[0099] In the second platform, USB 3.0 ports share a common register bit field. For example... Figure 6As shown, a 32-bit shared port control register is divided into multiple bit fields, each corresponding to a USB 3.0 port. For example, bit 16 corresponds to port 1, bit 17 to port 2, bit 18 to port 3, and bit 19 to port 4. A logic 1 indicates that the corresponding USB 3.0 port is disabled, and a logic 0 indicates that the corresponding USB 3.0 port is enabled. The shared register bit field design for USB 3.0 ports effectively reduces register address usage, but it also increases operational complexity. When modifying the configuration of a port, the current value of the register must be read, the target bit field modified, and then written back to avoid affecting the configuration of other ports.
[0100] The key feature of the second platform is that the disable operation must be performed in conjunction with the xHCI PORTSC register to shut down the port power. For example... Figure 7 As shown, PORTSC is a port status and control register defined in the xHCI specification. Each physical port corresponds to one PORTSC register within xHCI. The PORTSC register contains a PortPower bit, which controls the VBUS power supply to the corresponding port. When the PortPower bit is logic 1, VBUS power is enabled, and connected devices can operate normally; when the PortPower bit is logic 0, VBUS power is disabled, and the port is powered off.
[0101] In the second platform, if the disable bit of the port control register is written to a disable value but the PortPower bit of PORTSC is not simultaneously turned off, the VBUS power supply to the USB port still exists. In this state, although the xHCI controller will not transmit data through the port, the connected USB device can still receive power through VBUS, and the internal circuitry of the device remains operational. This not only means that the disable operation does not achieve the security effect of physical isolation, but may also generate standby power consumption due to the continuous power supply to the device. In some hardware designs, it may even cause the device to still be recognized by the operating system, rendering security control completely ineffective. Therefore, in the second platform, the disable operation must simultaneously complete both register disablement and power-off.
[0102] The second platform execution submodule performs the following steps when disabling a USB 2.0 port: First, it reads the PORTSC register corresponding to the target USB 2.0 port via the PCIe indirect access submodule and clears its PortPower bit to zero, thereby shutting down the VBUS power supply to that USB 2.0 port. Second, it reads the PORTSC register of the corresponding USB 3.0 port via the PCIe indirect access submodule and clears its PortPower bit to zero, thereby shutting down the VBUS power supply to that USB 3.0 port. Then, it sets bit 31 of the corresponding USB 2.0 port control register to logic 1 via the PCIe indirect access submodule, i.e., writes a disable value, completing the disabling operation.
[0103] The reason for simultaneously shutting down the power supplies to both USB 2.0 and USB 3.0 ports in the above process is that the same physical USB socket contains both USB 2.0 and USB 3.0 signal lines, but both share the VBUS power supply pin. If only the PORTSC power bit corresponding to USB 2.0 is turned off without simultaneously turning off the PORTSC power bit corresponding to USB 3.0, VBUS can still maintain power supply through the power control path of the USB 3.0 line, and the power supply to the port cannot be truly cut off. The above design of this application ensures that the physical power supply to the port is completely cut off regardless of whether the device is connected to a USB 2.0 line or a USB 3.0 line.
[0104] The second platform execution submodule performs the following steps when disabling a USB 3.0 port: First, it reads the PORTSC register corresponding to the target USB 3.0 port via the PCIe indirect access submodule, clears its PortPower bit to zero, and shuts off the USB 3.0 VBUS power supply to that port. Second, it reads the USB 2.0 PORTSC register corresponding to that port via the PCIe indirect access submodule, clears its PortPower bit to zero, and shuts off the USB 2.0 VBUS power supply. Then, it reads the current value of the USB 3.0 shared port control register via the PCIe indirect access submodule, sets the bit field corresponding to the target port to logic 1, leaves other bit fields unchanged, and then writes the modified value back to the shared port control register, completing the disabling operation.
[0105] In the enabling operation of the second platform, the process is relatively simple because it does not require powering off. To enable a USB 2.0 port, the 31st bit of the corresponding USB 2.0 port control register is cleared via the PCIe indirect access submodule. To enable a USB 3.0 port, the current value of the USB 3.0 shared port control register is read via the PCIe indirect access submodule, the bit field corresponding to the target port is cleared, while other bit fields remain unchanged. The modified value is then written back to the register.
[0106] In the second platform, writing to the port control register does not require Flash write protection unlocking and recovery operations, nor does it require block erasure, thus its operation speed is much faster than the first platform. The module in this application achieves optimal operational performance matching the platform characteristics by automatically routing submodules based on platform identification, enabling upper-layer callers to obtain the best operational performance when using the same API.
[0107] During the startup process of a computer system, various hardware components and software modules are initialized and configured in a specific order. For the USB port management module of this application, there is an optimal calling window, namely after the PCI bus enumeration is completed and before the xHCI driver is initialized. During this window, the PCIe bus has completed the enumeration of all PCIe devices, including the USB bridge chip, and the BAR base address of the USB bridge chip has been allocated and written into the BAR register. Therefore, the PCIe indirect access submodule can obtain the correct base address and access the internal registers of the USB bridge chip. At the same time, the xHCI driver has not yet been loaded and initialized, so the driver layer will not perform any read or write operations on the port management register, and will not overwrite or interfere with the management configuration of this module.
[0108] During the module initialization phase, the timing control submodule determines whether the current state is within the aforementioned call window by checking the system status. In one specific embodiment of this application, the timing control submodule determines the current stage by checking the system startup stage flag. In a UEFI firmware environment, the system startup process sequentially goes through stages such as SEC, PEI, DXE, BDS, and TSL. The module of this application is called at an appropriate sub-stage of the DXE stage, at which point the PCI bus driver has completed enumeration, but the xHCI driver has not yet started. If the upper-layer caller attempts to call the interface of this module outside the window, the timing control submodule will return a timing error code, indicating an inappropriate call timing.
[0109] The timing control submodule is also responsible for inserting necessary delays into the Flash operation sequence of the first type of platform. As mentioned earlier, the Flash controller needs a certain amount of time to complete its internal state transition when executing command switching. If the software continuously sends commands to the Flash controller without sufficient interval time, the later command may be received before the previous command is completed, leading to command conflicts or execution errors. The timing control submodule inserts delays of predetermined durations between each step of the Flash write-protection release sequence, after the block erase operation, and between each step of the write-protection recovery sequence.
[0110] In a preferred embodiment of this application, the timing control submodule employs the following delay strategy: a 10-millisecond delay between each step of the write protection release sequence, a 30-millisecond delay after the block erase operation, and a 10-millisecond delay between each step of the write protection recovery sequence.
[0111] In summary, the cross-platform USB bridge port management method provided in this application has the following beneficial effects: 1. This application encapsulates the complex low-level operations of USB port management into a standardized module. The caller only needs to call one line of API to enable or disable the port without having to worry about details such as low-level register addresses, Flash constraints and PORTSC coordination, which greatly reduces customer access and maintenance costs and shortens the product development cycle based on different hardware platforms.
[0112] 2. The module in this application achieves cross-platform compatibility through the platform identification sub-module. The same module can automatically adapt to two different hardware architecture platforms. The client-side code does not need to be developed and maintained separately for platform differences, which significantly improves code reusability and reduces the complexity of software version branch management caused by multi-platform adaptation.
[0113] 3. The backup and recovery atomic write mechanism designed for the Flash storage characteristics of the first platform in this application effectively prevents the erroneous modification of the state of adjacent ports caused by block erase operations, ensures the atomic consistency of port configuration, avoids the problem of loss of the control state of other configured ports due to erase operations, and improves the reliability of system configuration.
[0114] 4. The operation process of turning off the power first and then writing the disable value designed for the second type of platform in this application ensures that the disable operation can completely cut off the physical power supply of the port, so that the disabled port can achieve the safety effect of physical isolation. This solves the problem that simply writing the disable bit cannot completely shut down the port, and improves the effectiveness of security control.
[0115] 5. This application constrains the timing of module calls to be after PCI enumeration is completed and before xHCI driver initialization through the timing control submodule. This effectively avoids the driver initialization from overriding the port management configuration, ensuring that the management configuration remains effective after the operating system starts. This solves the timing conflict problem in the existing solution where the management configuration is easily overridden by the driver.
[0116] 6. This application calculates the target register address through address offset mapping, enabling the module to automatically locate the control register of any port through port type and port index parameters, without having to store hard-coded addresses for each port, thus reducing the module's storage overhead and improving code maintainability and scalability.
[0117] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
[0118] It will be apparent to those skilled in the art that this application is not limited to the details of the exemplary embodiments described above, and that this application can be implemented in other specific forms without departing from the spirit or essential characteristics of this application. Therefore, the embodiments should be considered illustrative and non-limiting in all respects, and the scope of this application is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within this application. No reference numerals in the claims should be construed as limiting the scope of the claims.
Claims
1. A cross-platform USB bridge chip port management method, characterized in that, This is applied to a cross-platform USB bridge chip port management module, which includes an interface layer, a platform identification submodule, a PCIe indirect access submodule, a first type of platform execution submodule, and a second type of platform execution submodule. The cross-platform USB bridge port management method includes: The interface layer receives a call request, which includes the target port's port type parameter, port index parameter, and operation type parameter. The platform identification submodule detects the current hardware platform category, which includes a first type of platform and a second type of platform; and the USB port control register of the first type of platform is stored in the off-chip Flash address field, while the USB port control register of the second type of platform is a normal read and write register without Flash restrictions. The target address of the internal target register of the USB bridge chip is determined based on the port type parameter and the port index parameter. When identified as the first type of platform, the first type of platform execution submodule is invoked, and a register access sequence conforming to the physical characteristics of the first type of platform is generated according to the operation type parameter for the target address in the port control register stored in the off-chip Flash address field. When identified as the second type of platform, the second type of platform execution submodule is invoked. Based on the operation type parameter, the enable control bit of the target address in the port control register is selected, and combined with the port power control bit, a register access sequence containing multi-register linkage control is generated. The PCIe indirect access submodule performs indirect addressing read and write operations on the target address through the PCIe configuration space register according to the register access sequence, so as to enable or disable the target port.
2. The cross-platform USB bridge port management method according to claim 1, characterized in that, The steps for generating a register access sequence that conforms to the physical characteristics of the first type of platform, for the target address stored in the port control register in the off-chip Flash address field, include: Before performing a write operation on the off-chip Flash address field, a Flash write protection release operation is performed; When it is necessary to change the target bit from 0 to 1, a block erase operation is performed on the off-chip Flash before the write operation is executed; wherein, writing the target bit to 1 represents port enable, and writing the target bit to 0 represents port disable. After the write operation is completed, a Flash write protection recovery operation is performed.
3. The cross-platform USB bridge port management method according to claim 2, characterized in that, The steps by which the PCIe indirect access submodule performs indirect addressing read / write operations on the target address through the PCIe configuration space register according to the register access sequence include: When the port control register is disabled, after the Flash write protection is released, the target bit of the target register is changed from 1 to 0 through the PCIe configuration space register, while the remaining bits remain 1; after the write is completed, the Flash write protection is restored. When the port control register is enabled, after the Flash write protection is released, all current values of the target register and associated register are read and recorded; after the block erase operation is performed on the off-chip Flash, all bits except the target bit in the target register and associated register are restored, and the target bit is written to 1; after the writing is completed, the Flash write protection is restored.
4. The cross-platform USB bridge port management method according to claim 2, characterized in that, The port types include USB 2.0 and USB 3.0, and the steps for generating a register access sequence that conforms to the physical characteristics of the first type of platform include: When the port type is USB 2.0 and a disable operation is performed: Execute the Flash write protection unlock operation; clear the corresponding bit in the first port control register according to the port index; execute the Flash write protection restore operation; When the port type is USB 2.0 and an enable operation is performed: Execute the Flash write protection unlock operation; read and record the current values of the first port control register and the second port control register; execute the Flash block erase operation; restore the second port control register to the recorded value, set the corresponding bit in the first port control register and restore the remaining bits to the recorded value; execute the Flash write protection restore operation; When the port type is USB 3.0 and a disable operation is performed: Execute the Flash write protection unlock operation; clear the corresponding bit in the second port control register according to the port index; execute the Flash write protection restore operation; When the port type is USB 3.0 and an enable operation is performed: Execute the Flash write protection unlock operation; read and record the current values of the first port control register and the second port control register; execute the Flash block erase operation; restore the first port control register to the recorded value, set the corresponding bits in the second port control register and restore the remaining bits to the recorded value; execute the Flash write protection restore operation; The first port control register is used to control the USB 2.0 port, and the second port control register is used to control the USB 3.0 port.
5. The cross-platform USB bridge port management method according to claim 1, characterized in that, The port types include USB 2.0 and USB 3.
0. When the operation type is disabled, the register access sequence generated by the second type of platform execution submodule includes: The power control position of the corresponding USB 2.0 port is set to the power-off state via the xHCI PORTSC register. The power control position of the corresponding USB 3.0 port is set to the power-off state via the xHCI PORTSC register. Write a disabled value to the target bit of the corresponding USB 2.0 port control register or USB 3.0 port control register.
6. The cross-platform USB bridge port management method according to claim 5, characterized in that, The register access sequences generated by the second type of platform execution submodule include: When the port type is USB 2.0 and a disable operation is performed: power off the corresponding USB 2.0 port; power off the corresponding USB 3.0 port; set the enable control bit of the corresponding USB 2.0 independent port management register to 1; When the port type is USB 3.0 and a disable operation is performed: power off the corresponding USB 2.0 port; power off the corresponding USB 3.0 port; set the bit field corresponding to the port index in the USB 3.0 common port management register to 1.
7. The cross-platform USB bridge port management method according to claim 1, characterized in that, The PCIe configuration space of the USB bridge chip includes address registers, data registers, and access control registers; The steps by which the PCIe indirect access submodule performs indirect addressing read / write operations on the target address through the PCIe configuration space register according to the register access sequence include: When performing a write operation, the target register address is written to the address register; the value to be written is written to the data register; a 1 is written to the write request initiation bit of the access control register to trigger the write transaction; the write request initiation bit of the access control register is polled until the write request initiation bit is automatically cleared to confirm that the write operation is complete. When performing a read operation, the target register address is written to the address register; a 1 is written to the read request initiation bit of the access control register to trigger a read transaction; the read request initiation bit of the access control register is polled until the read request initiation bit is automatically cleared; and the current value of the target register is read from the data register.
8. The cross-platform USB bridge port management method according to claim 7, characterized in that, The steps for determining the target address of the internal target register of the USB bridge chip based on the port type parameter and the port index parameter include: Obtain the PCIe base address of the USB bridge chip; Based on the port type parameter, determine the register group base offset corresponding to the port type; Calculate the index offset of the target port within the register group based on the port index parameter; The target address of the target register is the sum of the PCIe base address, the register set base offset, and the index offset; and the target address is written into the address register when performing a read or write operation.
9. The cross-platform USB bridge port management method according to claim 1, characterized in that, The cross-platform USB bridge port management module also includes a timing control submodule, and the method further includes: Before the PCIe indirect access submodule performs indirect addressing read / write operations, the timing control submodule confirms that the current system time is within the time window after the PCI bus enumeration is completed and before the xHCI driver is initialized; and inserts a predetermined delay between each step of the register access sequence executed by the first type of platform execution submodule.
10. A cross-platform USB bridge port management module, characterized in that, The cross-platform USB bridge port management module includes: The interface layer provides a unified application programming interface to the outside world, receives call requests containing port type, port index, and operation type, and returns the operation result; and the port type parameter and port index parameter are used to determine the target address of the internal target register of the USB bridge chip. The platform identification submodule is used to automatically detect the current hardware platform category during module initialization. The hardware platform category includes a first type platform and a second type platform. The USB port control register of the first type platform is stored in the off-chip Flash address field, while the USB port control register of the second type platform is a normal read / write register without Flash restrictions. The first type of platform execution submodule is used to generate a register access sequence that conforms to the physical characteristics of the first type of platform when the hardware platform category is the first type of platform, based on the operation type parameter and targeting the target address in the port control register stored in the off-chip Flash address field. The second type of platform execution submodule is used to generate a register access sequence containing multi-register linkage control based on the operation type parameter, the enable control bit of the target address in the port control register, and the port power control bit, when the hardware platform category is the second type of platform. The PCIe indirect access submodule is used to perform indirect addressing read and write operations on the target address through the PCIe configuration space register according to the register access sequence, so as to enable or disable the target port.
