CN116821033A - PCIe (peripheral component interconnect express) equipment control method and device - Google Patents

PCIe (peripheral component interconnect express) equipment control method and device Download PDF

Info

Publication number
CN116821033A
CN116821033A CN202310779405.9A CN202310779405A CN116821033A CN 116821033 A CN116821033 A CN 116821033A CN 202310779405 A CN202310779405 A CN 202310779405A CN 116821033 A CN116821033 A CN 116821033A
Authority
CN
China
Prior art keywords
identifier
slot
equipment
bridge
terminal
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310779405.9A
Other languages
Chinese (zh)
Inventor
董世江
窦志冲
刘波
宋凯
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Inspur Intelligent Technology Co Ltd
Original Assignee
Suzhou Inspur Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Suzhou Inspur Intelligent Technology Co Ltd filed Critical Suzhou Inspur Intelligent Technology Co Ltd
Priority to CN202310779405.9A priority Critical patent/CN116821033A/en
Publication of CN116821033A publication Critical patent/CN116821033A/en
Pending legal-status Critical Current

Links

Abstract

The application relates to a PCIe device control method and device. The method comprises the following steps: when scanning to a bridge device from a system, judging whether the bridge device supports hot plug or not; when the bridge equipment supports hot plug, an identifier is allocated to a slot connected with the bridge equipment; the identifier is a unique identifier; and distributing the identifier of the slot to the terminal equipment in the slot, and initializing the terminal equipment through an equipment driver. By adopting the method, the unique identifier is allocated to the slot connected with the bridge device supporting hot plug in advance in the process of device scanning, and the identifier of the slot is allocated to the terminal device after the terminal device is inserted into the slot, so that the disc character drift caused by the hot plug operation of the terminal device is prevented.

Description

PCIe (peripheral component interconnect express) equipment control method and device
Technical Field
The application relates to the field of PCIe device control, in particular to a PCIe device control method and device.
Background
PCIe (peripheral component interconnect express ) is a third generation I/O bus standard behind the PCI bus, and its main advantages over the PCI bus are high data transfer rates, high interference immunity, long transfer distances, and low power consumption. PCIe is widely used in consumer computer devices, enterprise servers, and switch systems, and devices using PCIe are referred to as PCIe devices.
With the development of science and technology, the performance requirements of computers are increasing, and the computers are required to have high storage capacity while having high computing power. The computing power mainly depends on the CPU of the computer, the storage power mainly depends on the hard disk, and when the performance of the CPU and the hard disk reach a certain degree, the processing power of the whole computer depends on the processing power of the whole computer on data. In order to meet the requirements of faster and higher data processing, a hard disk interface standard NVME (non-volatile memory express, non-volatile memory host controller interface specification) was created, and a hard disk conforming to this standard is called an NVME hard disk.
When using a computer system, if a component is damaged, such as a disk, it is often necessary to power down the system before the system can be replaced. For large systems, once the power is off, the operation is stopped, which can have serious impact. In order to avoid the influence of frequent power failure on the operation of a large-scale system, a hot plug technology is proposed, wherein the hot plug technology comprises hot addition and hot deletion operations, and can realize the replacement of a hard disk under the condition of no power failure. Most of the current operating systems support NVME hot plug technology, and when the hot plug operation of the device is performed on the system, different actions are performed by interrupting the hot plug driver.
However, the conventional character device adding method has a problem of a character shift. For example: the slot1 is inserted with a device nvme1, and the device corresponding to the disc identifier is 1; the slot2 is inserted with the device nvme2, the device corresponding to the identifier is 2, and at this time, the corresponding relationship of the character device in the operating system is: character device/dev/nvme 1 points to nvme1 disk and character device/dev/nvme 2 points to nvme2 disk. When the device nvme1 and the device nvme2 are pulled out, the device nvme2 is inserted first, then the device nvme1 is inserted, the identifier of the device nvme2 becomes 1, the identifier of the device nvme1 becomes 2, and at this time, the character device under the operating system can also be changed correspondingly: the character device/dev/nvme 1 actually points to nvme2 disk and the character device/dev/nvme 2 actually points to nvme1 disk. Since the identifier of nvme1 becomes 2, which is a very serious error for upper layer traffic, in case of a drift of the disc, the configuration of the traffic needs to be changed to make the traffic proceed normally, which is catastrophic for the uninterrupted type of traffic. Therefore, a method needs to be found to avoid the disc symbol drift caused by the hot plug operation of the device, thereby affecting the normal operation of the upper layer service.
Disclosure of Invention
In view of the above, the present application is directed to a PCIe device control method and apparatus, so as to solve the problem of disc symbol drift caused by hot plug operation of the device.
A first aspect of an embodiment of the present application provides a PCIe device control method, where the method includes:
when scanning to a bridge device from a system, judging whether the bridge device supports hot plug or not;
when the bridge equipment supports hot plug, an identifier is allocated to a slot connected with the bridge equipment; the identifier is a unique identifier;
and distributing the identifier of the slot to the terminal equipment in the slot, and initializing the terminal equipment through an equipment driver.
Optionally, when scanning from the system to the bridge device, determining whether the bridge device supports hot plug includes:
inquiring whether the bridge device opens an interrupt function; the interrupt function includes MSI interrupt and MSI-X interrupt;
if the bridge device starts the interrupt function, further reading a register of the bridge device, and judging whether the bridge device supports hot plug or not;
if the bridge device does not start the interrupt function, the bridge device does not support hot plug.
Optionally, allocating an identifier to the slot to which the bridge device is connected, including:
Adding a variable for storing an identifier of the slot to a data structure corresponding to the bridge device;
an identifier is obtained and stored in the variable.
Optionally, assigning the identifier of the slot to the terminal device in the slot includes:
in the device driver, performing an operation of acquiring a bridge device connected to the slot;
reading a variable which stores the identifier of the slot from a data structure corresponding to the bridge device, and acquiring the identifier of the slot from the variable;
and allocating the identifier of the slot to the terminal equipment.
Optionally, allocating an identifier to the slot to which the bridge device is connected, including:
in the device driver, executing an operation of adding a variable for saving an identifier of the slot to a data structure corresponding to the bridge device;
an identifier is obtained and stored in the variable.
Optionally, assigning the identifier of the slot to the terminal device in the slot includes:
in the device driver, performing an operation of acquiring a bridge device connected to the slot;
reading a variable which stores the identifier of the slot from a data structure corresponding to the bridge device, and acquiring the identifier of the slot from the variable;
And allocating the identifier of the slot to the terminal equipment.
Optionally, the PCIe device control method further includes:
initializing configuration of the system when the system is started;
initializing a data structure of the PCIe device, and generating a data structure for describing information of the PCIe device; the data structure describing PCIe device information includes: a bus to which the device belongs, a device type, and a device ID; the data structure for describing PCIe equipment information is a tree structure;
scanning the equipment in the system, and judging the type of the currently scanned equipment; the device is a bridge device or a terminal device, and any terminal device is connected with one bridge device one to one.
Optionally, the PCIe device control method further includes:
corresponding equipment resources are allocated for the currently scanned terminal equipment; the equipment resources comprise bus resources and memory resources;
and calling a bus detection interface to match corresponding device drivers for the terminal device.
Optionally, the PCIe device control method further includes:
when the bridge equipment supports hot plug, reserving resources to be allocated for the bridge equipment; the resources to be allocated comprise bus resources and memory resources;
And returning and continuing to scan other devices in the system when the bridge device does not support hot plug.
Optionally, the PCIe device control method further includes:
when the bridge device supports hot plug, an interrupt callback function is created;
creating an interrupt work queue and an event processing callback function through the interrupt callback function;
the event processing callback function executes adding or deleting operation according to the hot plug behavior of the terminal equipment in the system, and the event processing callback function comprises the following steps:
obtaining interrupt information through the event processing callback function, and judging the interrupt type;
if the interrupt type is equipment addition, rescanning equipment in the system, and calling the equipment driver when newly added terminal equipment is scanned;
executing the operation of acquiring the bridge equipment connected with the slot where the newly added terminal equipment is located in the equipment driver;
reading a variable which stores the identifier of the slot where the newly added terminal equipment is located from a data structure corresponding to the bridge equipment, and acquiring the identifier of the slot from the variable;
assigning an identifier of the slot to the newly added terminal device;
Initializing the newly added terminal device in the device driver;
if the interrupt type is equipment deletion, a deletion operation function is called to stop corresponding terminal equipment, corresponding data in a data structure corresponding to bridge equipment connected with the terminal equipment is deleted, and equipment resources distributed to the terminal equipment are released; the device resources include bus resources and memory resources.
According to a second aspect of an embodiment of the present application, there is provided a PCIe device control apparatus for implementing the PCIe device control method provided in the first aspect of the embodiment of the present application, the apparatus includes:
a device scanning module configured to determine whether a bridge device supports hot plug when scanning from a system to the bridge device;
an identifier allocation module configured to allocate an identifier to a slot to which the bridge device is connected when the bridge device supports hot plug;
and the device initializing module is configured to allocate the identifier of the slot to the terminal device in the slot and initialize the terminal device through a device driver.
By adopting the PCIe equipment control method provided by the application, when the bridge equipment is scanned in the system, whether the bridge equipment supports hot plug is judged, when the bridge equipment supports hot plug, a unique identifier is allocated for a slot connected with the bridge equipment, and when the terminal equipment is inserted into the slot, the identifier of the slot can be allocated to the terminal equipment.
In the PCIe device control method provided by the application, whether the currently scanned bridge device supports hot plug is judged by carrying out device scanning in the system, a unique identifier is allocated to a slot connected with the bridge device supporting hot plug in advance in the device scanning process, and after the terminal device is inserted into the slot, the identifier of the slot is allocated to the terminal device, so that the disk character drift caused by the hot plug operation of the terminal device is prevented.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments of the present application will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flowchart of a PCIe device control method according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a PCIe device control apparatus according to an embodiment of the present application;
FIG. 3 is a flow chart illustrating initialization of a PCIe device in accordance with one embodiment of the present application;
FIG. 4 is a flow chart of PCIe device initialization in the related art;
FIG. 5 is a flow chart of performing hot plug management according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all embodiments of the application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
It should be appreciated that reference throughout this specification to "one embodiment" or "an embodiment" means that a particular feature, structure or characteristic described in connection with the embodiment is included in at least one embodiment of the present application. Thus, the appearances of the phrases "in one embodiment" or "in an embodiment" in various places throughout this specification are not necessarily all referring to the same embodiment. Furthermore, the particular features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
In various embodiments of the present application, it should be understood that the sequence numbers of the following processes do not mean the order of execution, and the order of execution of the processes should be determined by the functions and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
Reference will now be made in detail to exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numbers in different drawings refer to the same or similar elements, unless otherwise indicated. The implementations described in the following exemplary examples do not represent all implementations consistent with the application. Rather, they are merely examples of apparatus and methods consistent with aspects of the application as detailed in the accompanying claims.
It should be noted that, without conflict, the embodiments of the present application and features of the embodiments may be combined with each other.
The hot plug technology is the hot plug technology, and the hot plug allows a user to take out and replace damaged components such as a hard disk, a power supply or a board card under the condition of not shutting down the system and cutting off the power supply, and the hot plug technology can improve the reliability, expansibility and flexibility of the system, and simultaneously enables the system to have quick maintainability, redundancy and timely recovery capability to disasters.
Hot plug of computer systems includes hot add and hot delete. The hot addition is mainly to read register information of the slot, judge whether a device insertion signal exists according to the information, if so, further traverse the slot, finally call to a hard disk drive, and create a file in a system and add the device in the hard disk drive, thereby completing the initialization of the whole device.
The system is provided with character equipment and block equipment, wherein the character equipment refers to equipment which is accessed sequentially in a byte stream serial sequence mode, the reading and writing of the character equipment are performed by taking bytes as units, and common character equipment comprises a mouse, a keyboard and the like; the block device refers to a device capable of reading data with a certain length from any position of the device, and common block devices include a hard disk, a magnetic disk, a U disk and the like. The terminal devices in the system are usually character devices, and when adding the terminal devices, the driver obtains a unique identification ID through an IDA (an identifier allocation mechanism) mechanism, and then creates a corresponding terminal device according to the identification. The embodiment aims to solve the problem of the drive letter drift caused by the hot plug operation of the terminal equipment in the system.
For PCIe initialization, the devices scanned during initialization are classified into two types, terminal devices and bridge devices. The terminal equipment refers to computer external equipment such as a hard disk, a memory card and the like. Bridge devices are a special device in PCIe, and are mainly used for expanding other types of devices, such as terminal devices and bridge devices, that is, one bridge device may be connected to a terminal device or may be connected to another bridge device. In this embodiment, all the terminal devices are connected to the bridge device one to one, and one bridge device supporting hot plug also extends only one hot plug terminal device.
FIG. 4 is a flow chart of PCIe device initialization in the related art. As shown in fig. 4, in a general case, the system performs the procedure of initializing the PCI device as follows:
s1: the system is initialized at system start-up. The system initialization mainly refers to a part of settings performed after the system is started, such as the initialization of a memory, the setting of enabling or disabling certain functions of the system, and the like;
s2: after the system is initialized, initializing a PCIe structure, wherein the initialization refers to establishing a data structure for describing PCIe equipment information in the system, the data structure comprises information such as buses, equipment types, equipment IDs and the like of equipment in the system, and in order to conveniently manage all PCIe equipment, all PCIe equipment structures are connected in series to form a tree structure;
s3: entering a device scanning stage after initializing a PCIe structure, wherein the stage mainly comprises the steps of scanning which PCIe devices exist in a system;
s4: when the terminal equipment is scanned, corresponding equipment resources are allocated to the terminal equipment, and then equipment driving is called to initialize the terminal equipment;
s5: when the bridge device is scanned, some resources, such as bus number resources and memory resources, are reserved for the bridge device because other devices need to be connected behind the bridge device;
S6: initialization of the PCIe device is performed, a unique identifier is dynamically obtained in the device driver through an IDA mechanism (call IDA interface) for identifying device uniqueness, and then a corresponding device is created.
The IDA mechanism (drive allocation mechanism) is a method for the kernel to manage integer resources, which can manage a large number of integer resources and is very efficient in retrieving the resources.
In step S6, there is a problem of the disc drive drifting, because the device driver dynamically acquires an identifier to be assigned to the terminal device each time the terminal device is initialized, and thus, the disc drive drifting is caused once the terminal device is unplugged and reinserted.
Because the phenomenon of the disk symbol drift occurs in the system mainly due to the hot plug operation of the terminal equipment, and whether the bridge equipment connected with the slot of the hot plug supports the hot plug or not can be known through scanning a register in the system initialization process, the problem of the disk symbol drift can be solved by reserving an identifier for the slot in advance before the terminal equipment connected with the device driver is initialized by calling the device driver. In addition, the number of devices externally connected with an operating system is limited, and the number of storage devices is more limited, so that the reservation of the identifier for the external device in advance does not cause resource shortage of the identifier.
The application will be described in detail below with reference to the drawings in connection with embodiments.
FIG. 1 is a flowchart of a PCIe device control method according to an embodiment of the present application. As shown in fig. 1, the method includes:
s11: when scanning to a bridge device from a system, judging whether the bridge device supports hot plug or not;
s12: when the bridge equipment supports hot plug, an identifier is allocated to a slot connected with the bridge equipment; the identifier is a unique identifier;
s13: and distributing the identifier of the slot to the terminal equipment in the slot, and initializing the terminal equipment through an equipment driver.
In one embodiment, a device register in the system is scanned at system start-up, and when a bridge device is scanned, it is determined whether the bridge device supports hot plug. When it is known that the bridge device supports hot plug, a unique identifier may be assigned to the slot to which the bridge device is connected. In this embodiment, a bridge device supporting hot plug is only connected to one slot, i.e. one bridge device can only extend one terminal device.
When the external terminal equipment is inserted into the slot, the identifier of the slot is distributed to the terminal equipment, and then the subsequent initialization of the terminal equipment is completed through the equipment drive corresponding to the terminal equipment. In this embodiment, when the bridge device is scanned in the system initialization process, a unique identifier is reserved for a slot connected with the bridge device, and when a terminal device is inserted into the slot, the unique identifier of the slot is allocated to the terminal device, so as to solve the problem of disc identifier drift.
S111: inquiring whether the bridge device opens an interrupt function; the interrupt function includes MSI interrupt and MSI-X interrupt;
if the bridge device starts the interrupt function, further reading a register of the bridge device, and judging whether the bridge device supports hot plug or not;
if the bridge device does not start the interrupt function, the bridge device does not support hot plug.
In one embodiment, a first query is made as to whether the bridge device has turned on the interrupt function. When the bridge device is queried to start the interrupt function, further reading a register of the bridge device, and judging whether the bridge device supports hot plug. For example, reading the relevant value in the register to be 1 indicates that the bridge device supports hot plug, and reading the relevant value in the register to be 0 indicates that the bridge device does not support hot plug. If the bridge device is inquired that the interrupt function is not started, the bridge device is not supported by hot plug.
In this embodiment, the bridge device-on interrupt function may be an MSI interrupt or an MSI-X interrupt. MSI (Message Signaled Interrupts, message interrupt) is a way to generate an interrupt by writing information in memory, where the memory address is determined by the device driver and hardware device negotiations. Unlike conventional interrupt lines, MSI does not require a separate interrupt line, but rather communicates over the PCI bus; MSI-X (Extended Message Signaled Interrupts, extended message signal interrupt) is an interrupt scheme that extends on an MSI basis, allowing a device to use multiple independent interrupt signals, thereby improving the efficiency of interrupt processing. Are commonly used for applications requiring a high speed response, such as virtualization or high performance computing.
In this embodiment, when the bridge device is scanned, it is first determined whether the bridge device has turned on the interrupt function, so as to reserve an identifier for a slot connected to the bridge device that has turned on the interrupt function and supports hot plug, and when the bridge device has not turned on the interrupt function, it is not necessary to perform further determination, thereby saving system resources and accelerating initialization speed.
S121: adding a variable for storing an identifier of the slot to a data structure corresponding to the bridge device;
s122: an identifier is obtained and stored in the variable.
In one embodiment, when a system initiates a scan of devices within the system, an identifier is assigned to the scanned slot. Specifically, after the bridge device is scanned and the bridge device is determined to support hot plug, the slot connected with the bridge device can be inserted into the external terminal device, and at this time, in a data structure formed by initializing a PCIe structure, a variable for storing an identifier of the slot connected with the bridge device is added into a part of the corresponding structure of the bridge device. The variable is used to store an identifier of the slot, and the variable may be self-defined, for example, setting the variable name to int32_ t instance _ id.
When a variable is added to the data structure, an identifier is obtained that will be the unique identifier of the slot, which is stored in the variable for subsequent reading.
In this embodiment, the identifier may be acquired by calling an IDA interface, or may be acquired without using an IDA mechanism, and the method for acquiring the identifier in this embodiment is not particularly limited, so long as a unique identifier is acquired.
S131: in the device driver, performing an operation of acquiring a bridge device connected to the slot;
s132: reading a variable which stores the identifier of the slot from a data structure corresponding to the bridge device, and acquiring the identifier of the slot from the variable;
s133: and allocating the identifier of the slot to the terminal equipment.
In one embodiment, upon initializing a terminal device, a unique identifier is assigned to the terminal device in a device driver. Specifically, before the device driver initializes the terminal device, the device driver may first acquire the slot in which the terminal device is located, and find and acquire the bridge device connected to the slot.
Based on the bridge device finding the corresponding part from the data structure, the variable already stored in this part of the data structure is read from it, which variable is used to store the unique identifier of the slot, i.e. to read the unique identifier of the slot.
After reading the identifier of the slot, the device driver assigns the identifier of the slot to the terminal device. In this embodiment, the device driver reads the bridge device corresponding to the slot in which the terminal device is located, obtains the unique identifier of the slot from the data structure corresponding to the bridge device, and uses the identifier as the identifier of the terminal device, so that the identifier of the terminal device depends on the identifier of the slot in which the terminal device is located, and therefore, the terminal device performs hot plug operation without causing a change in the identifier, thereby avoiding occurrence of disc identifier drift.
S121': in the device driver, executing an operation of adding a variable for saving an identifier of the slot to a data structure corresponding to the bridge device;
s122': an identifier is obtained and stored in the variable.
In one embodiment, the slots may be assigned unique identifiers directly through a device driver. Specifically, a program or code statement for allocating an identifier to a slot is added in a device driver, a bridge device connected to the slot where the terminal device is located is searched, and a variable for storing the identifier of the slot is added to a data structure corresponding to the bridge device. After adding a variable, an identifier is obtained that will be the unique identifier of the slot, which is stored in the variable for subsequent reading.
S131': in the device driver, performing an operation of acquiring a bridge device connected to the slot;
s132': reading a variable which stores the identifier of the slot from a data structure corresponding to the bridge device, and acquiring the identifier of the slot from the variable;
s133': and allocating the identifier of the slot to the terminal equipment.
In one embodiment, after a unique identifier is assigned to a slot by a device driver, the device driver assigns the identifier of the slot to the terminal device. Specifically, the device driver obtains the bridge device connected to the slot where the terminal device is located, and reads the variable storing the unique identifier of the slot, that is, reads the unique identifier of the slot, from the data structure corresponding to the bridge device. The identifier of the slot is used as the identifier of the terminal equipment, and then the equipment driver continues to initialize the terminal equipment.
In this embodiment, an identifier is allocated to a slot in which a terminal device is located in a device driver, and the identifier of the slot is allocated to the terminal device, so that the identifier of the terminal device depends on the identifier of the slot in which the terminal device is located, and therefore, the terminal device performs hot plug operation without causing a change in the identifier, thereby avoiding occurrence of disc identifier drift.
In one embodiment, the PCIe device control method further includes:
s101: initializing configuration of the system when the system is started;
s102: initializing a data structure of the PCIe device, and generating a data structure for describing information of the PCIe device; the data structure describing PCIe device information includes: a bus to which the device belongs, a device type, and a device ID; the data structure for describing PCIe equipment information is a tree structure;
s103: scanning the equipment in the system, and judging the type of the currently scanned equipment; the device is a bridge device or a terminal device, and any terminal device is connected with one bridge device one to one.
In the above embodiment, before the system allocates a unique identifier to the terminal device, the system needs to perform an initialization configuration first, where the initialization configuration of the system mainly refers to a portion of settings performed after the system is started, such as initializing a memory, and setting that the system enables or disables certain functions.
After the system initialization, the initialization of the PCIe fabric is performed. The initialization of the PCIe structure mainly establishes a data structure describing PCIe device information in the system, and the data structure and connection information of each PCIe device are included, specifically, the data structure and connection information include information such as buses to which the device belongs, device types, device IDs and the like. For ease of management, in one embodiment, the data structures of PCIe devices are concatenated and form a tree structure for management.
After the PCIe data structure is initialized, the PCIe devices in the system are scanned. Specifically, the register of the device is read, if the data is successfully read, the existence of the device is indicated, and the register related to the type of the device is further read to acquire the type of the device.
S123: corresponding equipment resources are allocated for the currently scanned terminal equipment; the device resources include bus resources and memory resources.
In the above embodiment, when the terminal device is scanned, the corresponding device resource needs to be allocated to the terminal device, so that the terminal device after the subsequent initialization can be normally used. The resources allocated for the terminal device are typically bus resources and memory resources.
S124: and calling a bus detection interface to match corresponding device drivers for the terminal device.
The initialization for the terminal device needs to be performed by a device driver. In one embodiment, before the device is initialized by the device driver, the bus probe interface is also required to be called, the device driver is matched with the bus probe interface according to the type of the terminal device, and then the initialization of the terminal device is executed by the corresponding device driver.
S125: when the bridge equipment supports hot plug, reserving resources to be allocated for the bridge equipment; the resources to be allocated comprise bus resources and memory resources;
S126: and returning and continuing to scan other devices in the system when the bridge device does not support hot plug.
In the above embodiment, when the scanned bridge device supports hot plug, a part of resources need to be reserved for the bridge device, so that when the bridge device is externally connected with the terminal device, corresponding device resources are allocated for the terminal device. In this embodiment, the resources reserved for the bridge device include bus number resources and memory resources.
S104: when the bridge device supports hot plug, creating an event processing callback function, and executing adding or deleting operation by the event processing callback function according to the hot plug behavior of the terminal device in the system.
In one embodiment, the hot plug management of the external terminal device is performed by creating an event processing callback function, and in this embodiment, the hot plug management includes adding and deleting, and when the external terminal device is inserted into the slot or the terminal device is pulled out from the slot, the corresponding operation of adding or deleting the device is performed by the event processing callback function.
FIG. 5 is a flow chart of performing hot plug management according to an embodiment of the present application. As shown in fig. 5, in the hot plug management in the system, the adding and deleting of the terminal device includes the following steps:
S1041: and when the bridge equipment supports hot plug, creating an interrupt callback function, and creating an interrupt work queue and an event processing callback function through the interrupt callback function.
In one embodiment, when a bridge device is scanned, it is first checked whether the bridge device has an interrupt (MSI interrupt or MSI-X interrupt) function turned on. When the bridge device turns on the interrupt function, an interrupt callback function is created. The interrupt callback function may further create an interrupt work queue and an event handling callback function.
S1042: and obtaining interrupt information through the event processing callback function, and judging the interrupt type.
In this embodiment, the event processing callback function obtains interrupt information of the system, for example, interrupt information of device access or device extraction.
S1043: if the interrupt type is equipment addition, rescanning equipment in the system, and calling the equipment driver when newly added terminal equipment is scanned;
executing the operation of acquiring the bridge equipment connected with the slot where the newly added terminal equipment is located in the equipment driver;
reading a variable which stores the identifier of the slot where the newly added terminal equipment is located from a data structure corresponding to the bridge equipment, and acquiring the identifier of the slot from the variable;
Assigning an identifier of the slot to the newly added terminal device;
initializing the newly added terminal device in the device driver.
In this embodiment, after obtaining the interrupt information of the system, the event processing callback function further determines the type of the interrupt information. If the type of the interrupt information is device addition (i.e. event triggered by inserting a disk), rescanning the device in the system, if the newly added terminal device is scanned, further calling the device driver, and determining the identifier of the terminal device by reading the unique identifier of the slot in which the terminal device is located, thereby distributing the unique identifier to the newly added terminal device before the device driver initializes the terminal device, and preventing the disk from drifting.
The device driver acquires the identifier of the newly added terminal device by the method provided in the above embodiment, and then creates a corresponding character device in the system, thereby completing the adding process of the terminal device.
S1044: if the interrupt type is equipment deletion, a deletion operation function is called to stop corresponding terminal equipment, corresponding data in a data structure corresponding to bridge equipment connected with the terminal equipment is deleted, and equipment resources distributed to the terminal equipment are released; the device resources include bus resources and memory resources.
If the type of the interrupt information is device deletion (for example, an interrupt event triggered by the terminal device is pulled out), the event processing callback function calls a corresponding deletion operation function, stops the running process of the pulled out terminal device, deletes data corresponding to the pulled out terminal device, releases related resources, for example, deletes and releases bus resources and memory resources allocated to the terminal device when the terminal device is initialized, so as to be reallocated for the terminal device newly inserted into the slot later.
Based on the same inventive concept, an embodiment of the application provides a PCIe device control apparatus. Referring to fig. 2, fig. 2 is a schematic diagram of a PCIe device control apparatus 200 according to an embodiment of the present application. As shown in fig. 2, the apparatus includes:
a device scanning module 201 configured to determine, when scanning from a system to a bridge device, whether the bridge device supports hot plug;
an identifier allocation module 202 configured to allocate an identifier to a slot to which the bridge device is connected when the bridge device supports hot plug;
the device initializing module 203 is configured to assign an identifier of the slot to a terminal device in the slot, and initialize the terminal device through a device driver.
Optionally, the device scanning module 201 further comprises a querying sub-module configured to query whether the bridge device has turned on an interrupt function; the interrupt function includes MSI interrupt and MSI-X interrupt;
if the bridge device starts the interrupt function, further reading a register of the bridge device, and judging whether the bridge device supports hot plug or not;
if the bridge device does not start the interrupt function, the bridge device does not support hot plug.
Optionally, the PCIe device control apparatus 200 further includes a device identifier allocation module configured to add a variable for storing an identifier of the slot to a data structure corresponding to the bridge device;
an identifier is obtained and stored in the variable.
In one embodiment, the program or code statement that allocates the identifier and stores the corresponding identification data is packaged as a device identifier allocation module, which facilitates direct invocation whenever an identifier needs to be allocated. When an identifier is allocated to a slot or a device, the device identifier allocation module is called to allocate the identifier to the slot in advance in the process of executing scanning of the PCIe device; and when the terminal equipment is initialized, an identifier is allocated to the slot where the terminal equipment is positioned by calling the equipment identifier allocation module through the equipment driver. After the device identifier assignment module assigns the identifier, the identifier data is stored in the corresponding data structure.
Optionally, the PCIe device control apparatus 200 further includes a device identifier obtaining module configured to obtain a bridge device connected to the slot;
reading a variable which stores the identifier of the slot from a data structure corresponding to the bridge device, and acquiring the identifier of the slot from the variable;
and allocating the identifier of the slot to the terminal equipment.
In one embodiment, a program or code statement that reads the identifier of the slot from the associated data structure is packaged as a device identifier retrieval module, facilitating direct invocation whenever the identifier of the slot needs to be retrieved. And when the identifier of the slot needs to be read from the data structure, calling the equipment identifier acquisition module to read.
FIG. 3 is a flow chart illustrating initialization of a PCIe device according to one embodiment of the present application. As shown in fig. 3, in one embodiment, the initialization procedure for the terminal device is as follows:
s1: when the system is started, initializing the system;
s2: initializing a PCIe structure in the system;
s3: scanning devices in the system;
s4: in the process of scanning equipment, pre-distributing resources to bridge equipment supporting hot plug, and calling an equipment identifier distribution module to pre-distribute a unique identifier for a slot;
S5: when the terminal equipment is scanned, a device identifier acquisition module is called in the device driver to acquire the identifier of the slot where the terminal equipment is located, and the identifier is distributed to the terminal equipment to finish the subsequent initialization of the terminal equipment.
Optionally, the PCIe device control apparatus 200 further includes:
a system initialization module configured to initialize configuration of the system when the system is started;
the PCIe initialization module is configured to initialize a data structure of the PCIe device and generate a data structure for describing information of the PCIe device; the data structure describing PCIe device information includes: a bus to which the device belongs, a device type, and a device ID; the data structure for describing PCIe equipment information is a tree structure;
the device scanning module 201 is further configured to scan devices in the system and determine a type of a currently scanned device; the device is a bridge device or a terminal device, and any terminal device is connected with one bridge device one to one.
Optionally, the PCIe device control apparatus 200 further includes:
the resource allocation module is configured to allocate corresponding equipment resources for the currently scanned terminal equipment; the equipment resources comprise bus resources and memory resources;
And the drive matching module is configured to call a bus detection interface and match corresponding device drive for the terminal device.
Optionally, the resource configuration module is further configured to reserve a resource to be allocated for the bridge device when the bridge device supports hot plug; the resources to be allocated include bus resources and memory resources.
Optionally, the device scanning module 201 is further configured to return and continue scanning for other devices in the system when the bridge device does not support hot plug.
Optionally, the PCIe device control apparatus 200 further includes a hot plug processing module configured to create an event processing callback function when the bridge device supports hot plug, and perform an add or delete operation according to a hot plug behavior of a terminal device in the system.
Optionally, the hot plug processing module is further configured to obtain interrupt information through the event processing callback function, and determine an interrupt type;
if the interrupt type is added by the equipment, rescanning the equipment in the system, and initializing newly added terminal equipment in equipment driving;
if the interrupt type is equipment deletion, a deletion operation function is called to stop corresponding terminal equipment, corresponding data in a data structure corresponding to bridge equipment connected with the terminal equipment is deleted, and equipment resources are released; the device resources include bus resources and memory resources.
Optionally, the hot plug processing module is further configured to create an interrupt callback function;
and creating an interrupt work queue and the event processing callback function through the interrupt callback function.
The specific manner in which the various modules perform the operations in the apparatus of the above embodiments have been described in detail in connection with the embodiments of the method, and will not be described in detail herein.
The foregoing description of the preferred embodiments of the application is not intended to be limiting, but rather is intended to cover all modifications, equivalents, alternatives, and improvements that fall within the spirit and scope of the application.
For the purposes of simplicity of explanation, the methodologies are shown as a series of acts, but one of ordinary skill in the art will recognize that the present application is not limited by the order of acts described, as some acts may, in accordance with the present application, occur in other orders and concurrently. Further, those skilled in the art will recognize that the embodiments described in the specification are all of the preferred embodiments, and that the acts and components referred to are not necessarily required by the present application.
It will be apparent to those skilled in the art that embodiments of the present application may be provided as a method, apparatus, or computer program product. Accordingly, embodiments of the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the application may take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
Embodiments of the present application are described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. It is therefore intended that the following claims be interpreted as including the preferred embodiment and all such alterations and modifications as fall within the scope of the embodiments of the application.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article or terminal device comprising the element.
The PCIe device control method and apparatus provided by the present application are described in detail above, and specific examples are applied to illustrate the principles and embodiments of the present application, where the above description of the embodiments is only for helping to understand the method and core idea of the present application; meanwhile, as those skilled in the art will have variations in the specific embodiments and application scope in accordance with the ideas of the present application, the present description should not be construed as limiting the present application in view of the above.

Claims (11)

1. A PCIe device control method, comprising:
when scanning to a bridge device from a system, judging whether the bridge device supports hot plug or not;
when the bridge equipment supports hot plug, an identifier is allocated to a slot connected with the bridge equipment; the identifier is a unique identifier;
and distributing the identifier of the slot to the terminal equipment in the slot, and initializing the terminal equipment through an equipment driver.
2. The PCIe device control method of claim 1, wherein determining whether a bridge device supports hot plug when scanning from a system to the bridge device comprises:
Inquiring whether the bridge device opens an interrupt function; the interrupt function includes MSI interrupt and MSI-X interrupt;
if the bridge device starts the interrupt function, further reading a register of the bridge device, and judging whether the bridge device supports hot plug or not;
if the bridge device does not start the interrupt function, the bridge device does not support hot plug.
3. The PCIe device control method of claim 1, wherein assigning an identifier to the slot to which the bridge device is connected comprises:
adding a variable for storing an identifier of the slot to a data structure corresponding to the bridge device;
an identifier is obtained and stored in the variable.
4. The PCIe device control method according to claim 3, wherein assigning the identifier of the slot to the terminal device in the slot comprises:
in the device driver, performing an operation of acquiring a bridge device connected to the slot;
reading a variable which stores the identifier of the slot from a data structure corresponding to the bridge device, and acquiring the identifier of the slot from the variable;
and allocating the identifier of the slot to the terminal equipment.
5. The PCIe device control method of claim 1, wherein assigning an identifier to the slot to which the bridge device is connected comprises:
in the device driver, executing an operation of adding a variable for saving an identifier of the slot to a data structure corresponding to the bridge device;
an identifier is obtained and stored in the variable.
6. The PCIe device control method of claim 5, wherein assigning the identifier of the slot to the terminal device in the slot comprises:
in the device driver, performing an operation of acquiring a bridge device connected to the slot;
reading a variable which stores the identifier of the slot from a data structure corresponding to the bridge device, and acquiring the identifier of the slot from the variable;
and allocating the identifier of the slot to the terminal equipment.
7. The PCIe device control method of claim 1, further comprising:
initializing configuration of the system when the system is started;
initializing a data structure of the PCIe device, and generating a data structure for describing information of the PCIe device; the data structure describing PCIe device information includes: a bus to which the device belongs, a device type, and a device ID; the data structure for describing PCIe equipment information is a tree structure;
Scanning the equipment in the system, and judging the type of the currently scanned equipment; the device is a bridge device or a terminal device, and any terminal device is connected with one bridge device one to one.
8. The PCIe device control method of claim 1, further comprising:
corresponding equipment resources are allocated for the currently scanned terminal equipment; the equipment resources comprise bus resources and memory resources;
and calling a bus detection interface to match corresponding device drivers for the terminal device.
9. The PCIe device control method of claim 1, further comprising:
when the bridge equipment supports hot plug, reserving resources to be allocated for the bridge equipment; the resources to be allocated comprise bus resources and memory resources;
and returning and continuing to scan other devices in the system when the bridge device does not support hot plug.
10. The PCIe device control method of claim 1, further comprising:
when the bridge equipment supports hot plug, an interrupt callback function is created, and an interrupt work queue and an event processing callback function are created through the interrupt callback function;
The event processing callback function executes adding or deleting operation according to the hot plug behavior of the terminal equipment in the system, and the event processing callback function comprises the following steps:
obtaining interrupt information through the event processing callback function, and judging the interrupt type;
if the interrupt type is equipment addition, rescanning equipment in the system, and calling the equipment driver when newly added terminal equipment is scanned;
executing the operation of acquiring the bridge equipment connected with the slot where the newly added terminal equipment is located in the equipment driver;
reading a variable which stores the identifier of the slot where the newly added terminal equipment is located from a data structure corresponding to the bridge equipment, and acquiring the identifier of the slot from the variable;
assigning an identifier of the slot to the newly added terminal device;
initializing the newly added terminal device in the device driver;
if the interrupt type is equipment deletion, a deletion operation function is called to stop corresponding terminal equipment, corresponding data in a data structure corresponding to bridge equipment connected with the terminal equipment is deleted, and equipment resources distributed to the terminal equipment are released; the device resources include bus resources and memory resources.
11. PCIe device control apparatus for performing the method of any one of claims 1-10, comprising:
a device scanning module configured to determine whether a bridge device supports hot plug when scanning from a system to the bridge device;
an identifier allocation module configured to allocate an identifier to a slot to which the bridge device is connected when the bridge device supports hot plug;
and the device initializing module is configured to allocate the identifier of the slot to the terminal device in the slot and initialize the terminal device through a device driver.
CN202310779405.9A 2023-06-28 2023-06-28 PCIe (peripheral component interconnect express) equipment control method and device Pending CN116821033A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310779405.9A CN116821033A (en) 2023-06-28 2023-06-28 PCIe (peripheral component interconnect express) equipment control method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310779405.9A CN116821033A (en) 2023-06-28 2023-06-28 PCIe (peripheral component interconnect express) equipment control method and device

Publications (1)

Publication Number Publication Date
CN116821033A true CN116821033A (en) 2023-09-29

Family

ID=88127065

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310779405.9A Pending CN116821033A (en) 2023-06-28 2023-06-28 PCIe (peripheral component interconnect express) equipment control method and device

Country Status (1)

Country Link
CN (1) CN116821033A (en)

Similar Documents

Publication Publication Date Title
US7970974B2 (en) Method and system for adding or removing a logical unit of a USB mass storage device
US6081850A (en) Storing dynamically loaded device drivers on a mass storage device to support access to removable computer cards
JP4001877B2 (en) Automatic recovery from hardware errors in the I / O fabric
US7526578B2 (en) Option ROM characterization
CN110098946B (en) Method and device for deploying virtualized network element equipment
CN100451966C (en) Method and apparatus for discovering hardware in a data processing system
US10671403B2 (en) Method and apparatus for identifying hardware device in operating system
US7873754B2 (en) Structure for option ROM characterization
JPH10283210A (en) Virtual machine movement control system between virtual machine systems
CN112612623B (en) Method and equipment for managing shared memory
CN115185880B (en) Data storage method and device
CN109960569B (en) Virtualization processing method and device
WO2011142973A2 (en) Multi-level port expansion for port multipliers
CN111338689B (en) File calling method, device and equipment
CN110019475B (en) Data persistence processing method, device and system
CN115185874B (en) PCIE resource allocation method and related device
US20060047858A1 (en) ROM scan memory expander
CN106598696B (en) Method and device for data interaction between virtual machines
CN111522659B (en) Space use method and device
CN110471744B (en) Password modification method, device, equipment and computer readable storage medium
CN116821033A (en) PCIe (peripheral component interconnect express) equipment control method and device
US7039733B2 (en) Method, system, and apparatus for eliminating bus renumbering in a computer system
US6535969B1 (en) Method and apparatus for allocating free memory
CN114296810A (en) Operating system migration method, device, server and storage medium
CN110581869B (en) Resource allocation method, TLP packet processing method, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination