Equipment driver loading method and device, equipment and medium
By cached the running code of the target device to the second memory space in UEFI BIOS, the problem that the LEGACY PCIE OPTION ROM cannot be loaded when the first memory space is insufficient, and the normal operation of the device and efficient utilization of the memory space are achieved.
Patent Information
- Application Number
- CN202411755713.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-04-08
Smart Images

Figure CN119781838A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of device driver loading, and in particular to a device driver loading method, apparatus, device and medium. Background Art
[0002] At present, the BIOS of all machine manufacturers have switched to UEFI BIOS, but due to the inertia of the production environment of many cloud manufacturers, telecommunications, government departments, schools, and scientific research institutions, the system still uses the LEGACY system. Therefore, all PCIE devices on the whole machine still load the LEGACY PCIE OPTION ROM to run and initialize the PCIE devices. In order to be compatible with the user's LEGACY production environment, the UEFI BIOS of the whole machine manufacturer has implemented the LEGACY compatible module, and the LEGACY compatible module has implemented the LEGACYBIOS operating environment. Therefore, the UEFI BIOS has implemented the function of loading and running the LEGACY PCIEOPTION ROM based on the LEGACY compatible module. At the same time, the UEFI BIOS has implemented the function of starting the LEGACY system based on the LEGACY compatible module.
[0003] Although all machine manufacturers have switched to UEFI BIOS and implemented LEGACY compatible modules based on UEFI BIOS, the LEGACY compatible modules are still running in real mode, and the available memory space of the LEGACY compatible modules is still only 1M. The memory space that the PCIE OPTION ROM can run has not exceeded the 64K memory limit. Therefore, if there are too many PCIE devices connected to the server, the PCIE OPTION ROM will still encounter the situation of no available memory space, and the problem of the device not being able to run normally still exists.
[0004] Based on LEGACY BIOS, the size of the PCIE OPTION ROM loading range is basically fixed. All manufacturers have the problem that too many LEGACY BIOS devices cause some devices to be unable to load PCIE OPTION ROM and the devices cannot work properly. Therefore, how to load all LEGACY PCIE OPTION ROMs on UEFI BIOS and make the devices work properly needs to be solved urgently. Summary of the invention
[0005] Based on the above technical problems, the embodiments of the present application provide a device driver loading method, apparatus, device and medium, aiming to complete the driver loading of each device and enable the device to work normally.
[0006] A first aspect of an embodiment of the present application provides a device driver loading method, the method comprising:
[0007] During the first initialization of the target device, loading the initialization code of the target device into the first memory space;
[0008] Running the initialization code of the target device for the first time in the first memory space to obtain the running code of the target device;
[0009] caching the running code of the target device into a second memory space, wherein the storage space size of the second memory space is larger than the storage space of the first memory space;
[0010] When a call to the target device is detected, obtaining the running code of the target device from the second memory space;
[0011] The execution code of the target device is executed in the first memory space.
[0012] Optionally, the method further comprises:
[0013] During the first initialization of the target device, determining the size of the initialization code of the target device;
[0014] In the first memory space, according to the size of the initialization code of the target device, a memory space of a corresponding size is allocated and the initialization code of the target device is executed.
[0015] Optionally, the first memory space is associated with a first working mode, and a maximum memory space in the first working mode is a first threshold; the method further includes:
[0016] A memory space greater than the first threshold is allocated from the system memory space as the second memory space.
[0017] Optionally, the first memory space is associated with a first working mode, and a maximum memory space in the first working mode is a first threshold; the method further includes:
[0018] Estimate the size of the running code of each of the multiple target devices to be connected;
[0019] A memory space that is larger than the first threshold and larger than the sum of sizes of the respective running codes of the plurality of target devices is allocated from the system memory space as the second memory space.
[0020] Optionally, after obtaining the running code of the target device, the method further includes:
[0021] The memory space occupied by the initialization code of the target device is released from the first memory space.
[0022] Optionally, the first memory space is associated with a first working mode, the second memory space is associated with a second working mode, and the second working mode is a default working mode;
[0023] Before loading the initialization code of the target device, it also includes:
[0024] Switching from the default working mode to the first working mode;
[0025] In the first working mode, the steps are performed: in the process of initializing the target device for the first time, loading the initialization code of the target device in the first memory space; running the initialization code of the target device for the first time in the first memory space to obtain the running code of the target device;
[0026] Switching from the first working mode to the second working mode;
[0027] In the second working mode, the steps of: caching the running code of the target device to a second memory space, wherein the storage space size of the second memory space is larger than the storage space of the first memory space; when a call to the target device is detected, obtaining the running code of the target device from the second memory space;
[0028] Switching from the second working mode to the first working mode;
[0029] In the first working mode, the step of executing: running the running code of the target device in the first memory space.
[0030] Optionally, caching the running code of the target device into a second memory space includes:
[0031] By interrupting the service, copying the running code of the target device to the second memory space, and recording the storage location of the running code in the first memory space and the storage location in the second memory space;
[0032] When a call to a target device is detected, obtaining the running code of the target device from the second memory space includes:
[0033] According to the called target device, query the storage location of the running code of the target device in the first memory space and the storage location in the second memory space;
[0034] The running code of the target device will be copied to the storage location in the first memory space according to the storage location in the second memory space.
[0035] A second aspect of an embodiment of the present application provides a device driver loading apparatus, the apparatus comprising:
[0036] An initialization code loading module, used to load the initialization code of the target device into the first memory space during the process of initializing the target device for the first time;
[0037] An initialization code running module, used to run the initialization code of the target device for the first time in the first memory space to obtain the running code of the target device;
[0038] a swap-in / swap-out module, configured to cache the running code of the target device to a second memory space, wherein the storage space size of the second memory space is larger than the storage space of the first memory space; and when a call to the target device is detected, obtain the running code of the target device from the second memory space;
[0039] The execution code execution module is used to execute the execution code of the target device in the first memory space.
[0040] Optionally, the initialization code loading module includes:
[0041] An initialization code determination submodule, used to determine the size of the initialization code of the target device during the process of initializing the target device for the first time;
[0042] The first memory space allocation submodule is used to allocate a memory space of a corresponding size in the first memory space according to the size of the initialization code of the target device and to run the initialization code of the target device.
[0043] Optionally, the swap-in and swap-out module includes:
[0044] The system memory space allocation submodule is used to allocate a memory space greater than the first threshold from the system memory space as the second memory space.
[0045] Optionally, the swap-in / swap-out module further includes:
[0046] The running code estimation submodule is used to estimate the size of the running code of each of the multiple target devices to be connected;
[0047] The system memory space allocation submodule is used to allocate a memory space larger than the first threshold and larger than the sum of the sizes of the running codes of the multiple target devices from the system memory space as the second memory space.
[0048] Optionally, the initialization code execution module includes:
[0049] The initialization code release submodule is used to release the memory space occupied by the initialization code of the target device from the first memory space.
[0050] Optionally, the initialization code loading module further includes:
[0051] A first working mode switching submodule, used for switching from the default working mode to the first working mode;
[0052] The second working mode switching submodule is used to switch from the first working mode to the second working mode.
[0053] Optionally, the swap-in / swap-out module further includes:
[0054] a swap-out submodule, used to copy the running code of the target device to the second memory space through interrupt service, and record the storage position of the running code in the first memory space and the storage position in the second memory space;
[0055] A storage location query submodule, used to query the storage location of the running code of the target device in the first memory space and the storage location in the second memory space according to the called target device;
[0056] The swap-in submodule is used to copy the running code of the target device to the storage location in the first memory space according to the storage location in the second memory space.
[0057] A third aspect of an embodiment of the present application provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, a device driver loading method as in the first aspect of an embodiment of the present application is implemented.
[0058] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the device driver loading method of the first aspect of the embodiment of the present application is implemented.
[0059] Through the device driver loading method of the embodiment of the present application, during the first initialization of the target device, the initialization code of the target device is loaded into the first memory space; the initialization code of the target device is run for the first time in the first memory space to obtain the running code of the target device; the running code of the target device is cached to the second memory space, and the storage space size of the second memory space is larger than the storage space of the first memory space; when a call to the target device is detected, the running code of the target device is obtained from the second memory space; and the running code of the target device is run in the first memory space.
[0060] In this embodiment, the initialization code for running the target device is loaded in the first memory space to obtain the running code of the target device, and then the running code of the target device is saved in the second memory space. When it is needed later, the running code saved in the second memory space is copied to the first memory space for running. In this way, the running and storage of the running code are executed separately in two memory spaces, which not only ensures that the space capacity in the first memory space will not be fully occupied due to the increase in devices, but also maintains sufficient memory space for code running, which also improves the efficiency of code running. The user's use of the target device is no longer limited by the memory space, which meets the user's usage needs, greatly improves the user's work efficiency, and solves the problem of not being able to load all target devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0062] Figure 1 is a flow chart of a device driver loading method proposed in one embodiment of the present application;
[0063] Figure 2 This is a flowchart of initializing and loading a device driver provided by an embodiment of the present application;
[0064] Figure 3 It is a flowchart of a target device call provided by an embodiment of the present application;
[0065] Figure 4 is a structural block diagram of a device driver loading apparatus provided by an embodiment of the present application;
[0066] Figure 5 It is a schematic diagram of an electronic device shown in an embodiment of the present application. DETAILED DESCRIPTION
[0067] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0068] In the drawings, the size of the constituent elements, the thickness of the layer or the area may be exaggerated for the sake of clarity. Therefore, any implementation of the present application is not necessarily limited to the size shown in the drawings, and the shape and size of the components in the drawings do not reflect the true proportion. In addition, the drawings schematically show ideal examples, and any implementation of the present application is not limited to the shape or value shown in the drawings.
[0069] Please refer to Figure 1 , Figure 1 This is a flow chart of a device driver loading method of the present application. Figure 1 As shown, the method may include steps S101 to S105:
[0070] Step S101: during the first initialization of a target device, loading the initialization code of the target device into a first memory space;
[0071] Step S102: running the initialization code of the target device for the first time in the first memory space to obtain the running code of the target device;
[0072] Step S103: caching the running code of the target device into a second memory space, wherein the storage space size of the second memory space is larger than the storage space size of the first memory space;
[0073] Step S104: when a call to a target device is detected, obtaining the running code of the target device from the second memory space;
[0074] Step S105: running the running code of the target device in the first memory space.
[0075] In the prior art, in the process of connecting and using multiple target devices, it is first necessary to load the device driver of the target device, perform the corresponding initialization loading according to the target device, that is, run the initialization code of the target device, and obtain the running code corresponding to the target device after the loading is completed, and save the running code in the first memory space, and release the space occupied by the initialization code that has been run; then load other target devices through the same process. However, in this process, due to the limitations of historical technology, the capacity of the first content space is fixed and limited. Therefore, with the growing demand for connecting target devices today, the first memory space is insufficient to meet the user's usage needs. After loading a certain number of target devices, the space will be full and other device drivers cannot be loaded.
[0076] Therefore, the present application proposes a device driver loading method, which obtains the target device's running code in the first memory space after the target device is initialized and loaded for the first time, transfers and saves the running code to the second memory space outside the first memory space, and releases the target device's initialization code and running code in the first memory space, wherein the second memory space is actually a storage space for storing the target device's running code in the system space, and the space memory size is larger than the first memory space. When the target device is needed later, the running code of the target device is copied and transferred from the second memory space to the first memory space for execution, and the running code in the first memory space is released after the execution is completed. In this way, a second memory space is opened to share the storage space pressure of the first memory space, and the two parts of the work required for loading the target device driver: running and storage, are allocated to the two memory spaces. The first memory space with limited space capacity is only used as a place for code running, and no code storage is performed. This not only ensures that the space capacity in the first memory space will not be fully occupied due to the increase in devices, but also maintains sufficient memory space for code running, which improves the efficiency of code running. The user's use of the target device is no longer limited by the memory space, which meets the user's usage needs and greatly improves the user's work efficiency.
[0077] Step S101: during the first initialization of a target device, an initialization code of the target device is loaded into a first memory space.
[0078] In this embodiment, the process of initializing the target device is that when the target device is first connected to the device bus of the present application, the device bus driver scans and detects the new target device, allocates resources to it and performs link training to obtain the initialization code required for the target device to load. Since multiple target devices are connected to the device bus, the initialization code of the target device needs to be loaded and run in the first memory space in sequence.
[0079] Step S102: running the initialization code of the target device for the first time in the first memory space to obtain the running code of the target device.
[0080] In this embodiment, the initialization code of the target device is loaded and run to obtain the running code of the target device. The running code is the code that needs to be loaded for the normal use and operation of the target device. Each running code corresponds to a target device. Therefore, when the target device is first connected to the device bus, it is necessary to perform initialization loading to obtain the running code of the target device so that the target device can be loaded and run normally in the subsequent use process.
[0081] Step S103: caching the running code of the target device into a second memory space, wherein the storage space size of the second memory space is larger than the storage space size of the first memory space.
[0082] In this embodiment, after obtaining the running code of the target device in the above steps, the running code is cached in the second memory space for storage. The second memory space is a memory space independent of the first memory space and is allocated for storing the device running code. In order to meet the increasing device loading requirements, the size of the second memory space should be larger than the size of the first memory space to ensure that all target devices connected to the device bus can be loaded and run.
[0083] Step S104: when a call to the target device is detected, the running code of the target device is obtained from the second memory space.
[0084] Through steps S101-S103, each target device connected to the device bus completes initialization loading, and the running code of each target device is obtained and stored in the second memory space. In actual use, when a target device needs to be used, a call command for the target device needs to be detected first. After the call command is detected, which target device needs to be called is queried according to the description in the call command, and then the corresponding running code of the target device is found in the second memory space.
[0085] Step S105: running the running code of the target device in the first memory space.
[0086] After the running code corresponding to the called target device is found in the second memory space in step S104, the running code is copied to the first running space for running and loading to complete the calling command of the target device.
[0087] In combination with the above embodiments, in one implementation, the present application further provides a device driver loading method, in which the above step S101 specifically further includes the following contents:
[0088] First, during the process of initializing the target device for the first time, the size of the initialization code of the target device is determined.
[0089] Due to the differences between the various target devices, the corresponding initialization codes are also different. Therefore, after obtaining the initialization code of the target device that needs to be initialized and loaded, it is necessary to first determine the size of the initialization code. The initialization code is stored in the target device. After the target device is connected to the device bus, the initialization code is obtained and loaded into the first memory space in sequence according to the preset initialization loading order. Since the first memory space needs to load different target devices, it is necessary to divide the area running inside the space according to the size of the initialization code of the target device.
[0090] Then, in the first memory space, according to the size of the initialization code of the target device, a memory space of a corresponding size is allocated and the initialization code of the target device is executed.
[0091] In the prior art, since the execution and storage of the corresponding codes of the target device are all in the first memory space, the division of the first memory space needs to have a basis. According to the size of the memory space occupied by the initialization code of the target device, it is determined whether there is enough memory space in the first memory space to load and execute the initialization code of the target device, and it is also necessary to confirm whether there is remaining space to store the newly loaded running code of the target device.
[0092] In the present application, although the first memory space is no longer used for storing running code, after obtaining the initialization code of the target device, it is still necessary to divide it into an area of corresponding size according to the size of the memory space it occupies, as the area for loading and running the initialization code in the first memory space, so as to ensure that the process of device initialization loading and running will not be affected by parts of other memory space areas, and reasonable division of areas will also help to carry out operations in subsequent processes.
[0093] In combination with the above embodiments, in one implementation, the present application further provides a device driver loading method, wherein the first memory space is associated with a first working mode, and the maximum memory space in the first working mode is a first threshold; the method further includes:
[0094] A memory space greater than the first threshold is allocated from the system memory space as the second memory space.
[0095] In this embodiment, operations of the first working mode need to be performed in the first memory space. Since the capacity of the first memory space is fixed and limited, in order to store more operating codes of the target device, according to past experience, the capacity of the first memory space is far from enough. Therefore, the maximum capacity of the first memory space under the first working mode is used to determine the first threshold, which is used as one of the criteria for determining the size of the second memory space.
[0096] After obtaining the first threshold, a part of the system memory space outside the first memory space is divided as the second memory space. The space capacity of the second memory space needs to be larger than the first threshold space to ensure that the problem of incomplete storage of code running on the target device can be improved.
[0097] In an optional embodiment, taking the expansion of the first memory space of the X86 system as an example, due to the inertia of the production environment of some users, such as many cloud vendors, telecommunications, government departments, schools, scientific research institutions, etc., at present, most of the whole machine equipment has been replaced with the second working mode (i.e. UEFI BIOS), there is still a need to use the first working mode (i.e. LEGACY BIOS), and it is necessary to load the target device driver corresponding to the first working mode. Therefore, in the prior art, the operation of the first working mode is realized by setting a compatible module in the system space running in the second working mode, but due to technical reasons, even if the system space capacity in the second working mode has far exceeded the first memory space, the first memory space can still only run in the first working mode, and the available memory space is fixed and limited. In this embodiment, the first memory space is not greater than 1M, so the limit is used as the first threshold, that is, a memory space greater than 1M is divided in the system space as the second memory space, which is used to store the running code of the target device initialized and generated in the first memory space.
[0098] In combination with the above embodiments, in one implementation, the present application further provides a device driver loading method, wherein the first memory space is associated with a first working mode, and the maximum memory space in the first working mode is a first threshold; the method further includes:
[0099] Estimate the size of the running code of each of the multiple target devices to be connected;
[0100] A memory space that is larger than the first threshold and larger than the sum of sizes of the respective running codes of the plurality of target devices is allocated from the system memory space as the second memory space.
[0101] In this embodiment, the target device running code is estimated based on the number of target devices connected to the device bus, that is, there may be multiple target devices that need to be loaded and run, and the total size of the storage space required for their corresponding running codes, which is used as one of the criteria for determining the size of the second memory space.
[0102] In the process of dividing the system space, it is necessary to consider the first threshold described in the above steps and the total capacity of the running code corresponding to each target device that may be connected to the device bus. The second memory space divided for storing the running code of the target device should be greater than the first threshold and can accommodate the running code of each target device. The larger value of the two shall prevail.
[0103] In an optional embodiment, in actual operation, since the system memory space in the second working mode has a much larger capacity than the first memory space, when the second memory space is divided according to the above standards, more memory space can be reserved in the second memory space to prepare for loading other new target devices during subsequent use.
[0104] In combination with the above embodiments, in one implementation, the present application further provides a device driver loading method. In the method, in the above step S102, after obtaining the running code of the target device, the method further includes the following contents:
[0105] The memory space occupied by the initialization code of the target device is released from the first memory space.
[0106] In an embodiment of the present application, when the target device is first connected to the device bus, the initialization code of the target device is loaded and run in the first memory space to obtain the running code of the target device. Based on the running code, the user can call the target device in the subsequent use process. It can be seen that the initialization code of the target device is actually for obtaining the running code of the target device. Therefore, after obtaining the running code, the initialization code of the target device has completed what it needs to complete and no longer needs to occupy the first memory space. After completing step S102, the memory space occupied by the initialization code of the target device can be released to make more available memory space for subsequent steps.
[0107] In combination with the above embodiments, in one implementation, the present application also provides a device driver loading method, wherein the first memory space is associated with a first working mode, the second memory space is associated with a second working mode, and the second working mode is a default working mode.
[0108] In the prior art, if the device used by the user runs in the first working mode by default, that is, there is only the first memory space in its system space, the device driver is loaded according to the prior art. Combined with the embodiment described above, the user checks the currently started working mode through the BIOS code. If it is the first working mode (that is, LEGACY BIOS), the second memory space described above does not exist, and the system startup operation can be performed normally according to the previous technology.
[0109] In the scenario proposed in the present application, combined with the contents described above, it can be seen that there is a first memory space in the present application, which is associated with the first working mode and is used to execute the operations required in the first working mode. At the same time, there is also a second memory space, which is associated with the second working mode. Except for the operations that must be performed in the first memory space, all operations are performed in the system space outside the first memory space (including the second memory space), so the second working mode is determined as the default working mode.
[0110] In combination with the embodiments described above, all parts of the system space except the first memory space work in the default working mode (i.e., UEFI BIOS). When operations in the first working mode (i.e., LEGACY BIOS) are required, the compatibility module is used to switch to the first working mode and perform corresponding operations in the first memory space.
[0111] In combination with the above embodiments, in one implementation, the present application further provides a device driver loading method. Before loading the initialization code of the target device, the method further includes:
[0112] First, switch from the default working mode to the first working mode.
[0113] Since the system runs in the default working mode under normal circumstances, after detecting that a new target device is connected to the device bus, it is necessary to switch to the first working mode through the compatible module to perform the initialization operation on the target device, and its specific content is shown in steps S101 to S102: in the process of initializing the target device for the first time, the initialization code of the target device is loaded in the first memory space; the initialization code of the target device is run for the first time in the first memory space to obtain the running code of the target device. The above steps all need to be run in the first working mode, so after switching to the first working mode, steps S101 to S102 are executed in the first memory space to obtain the running code of the target device.
[0114] Then, switch from the first working mode to the second working mode.
[0115] In the prior art, since the initialization code loading and the running code storage of the target device are both in the first memory space, there is no need to switch the working mode. In the present application, since the storage space of the first memory space is fixed and limited, the second memory space exists in the system space outside the first memory space and works in the second working mode, that is, the default working mode. Therefore, after obtaining the running code of the target device, it is necessary to switch from the first working mode to the second working mode to store the running code of the target device.
[0116] Therefore, it is necessary to execute step S103 in the second working mode: cache the running code of the target device to a second memory space, and the storage space size of the second memory space is larger than the storage space of the first memory space.
[0117] In an embodiment of the present application, the running code of the target device is copied from the first memory space through the swap-in / swap-out module, and then the swap-in / swap-out module carries the copied running code to switch the working mode from the first working mode to the second working mode, and accesses the second memory space in the second working mode, and stores the copied running code of the target device in the second memory space, thereby completing the initialization loading of the target device.
[0118] In the actual operation process, when the target device needs to be called to work, step S104 is executed: first, when the call for the target device is detected, the operation code of the target device is obtained from the second memory space. At this time, the swap-in and swap-out module works in the second working mode, accesses the second memory space and copies the corresponding device operation code in the second memory space according to the information of the called device.
[0119] Then, the swap-in / swap-out module switches from the second working mode to the first working mode; in the first working mode, step S105 is executed: running the running code of the target device in the first memory space.
[0120] In combination with the above embodiments, in one implementation, the present application further provides a device driver loading method, in which the above step S104 specifically further includes the following contents:
[0121] By interrupting the service, the running code of the target device is copied to the second memory space, and the storage position of the running code in the first memory space and the storage position of the running code in the second memory space are recorded.
[0122] In the embodiment of the present application, after the initialization code of the target device is loaded, the running code of the target device is obtained, and the swap-in and swap-out module needs to be called through the interrupt service to copy the running code from the first memory space to the second memory space. Among them, since the running code of the target device needs to be called when the target device is used, and the running code is copied and moved between the first memory space and the second memory space through the swap-in and swap-out module called by the interrupt service, the swap-in and swap-out module records the specific location where the running code is stored in the first memory space, and the location where the running code is stored in the second memory space after being stored in the second memory space, so as to ensure that subsequent calling operations can be traced.
[0123] In the actual operation process, when the target device needs to be called to work, first, when the call to the target device is detected, the operation code of the target device is obtained from the second memory space, including:
[0124] According to the called target device, the storage location of the running code of the target device in the first memory space and the storage location in the second memory space are queried; and the running code of the target device is copied to the storage location in the first memory space according to the storage location in the second memory space.
[0125] Since the storage location of the target device's running code is recorded in the swap-in / swap-out module, after receiving the call command to the target device, firstly, according to the information of the called target device, the storage location of the corresponding swap-in / swap-out module in the second memory space is queried, and the swap-in / swap-out module called by the interrupt service copies the running code at the corresponding location. Then, when moving the running code, the swap-in / swap-out module switches from the second working mode to the first working mode, and queries the location of the first memory space corresponding to the running code, and copies the copied running code of the target device to the corresponding location in its first memory space. The running code runs in the first memory space, responds to the call command to the target device, and after the running is completed, the memory space occupied by the running code in the first memory space is released to ensure the space margin in the first memory space.
[0126] In this embodiment, the specific initialization loading process can be found in Figure 2 , Figure 2 This is a flowchart of the device driver initialization loading provided by an embodiment of the present application, as shown in the figure:
[0127] First, a second memory space is allocated in the system space to store the running code of the target device, and then the first working mode is loaded to prepare for loading the initialization code of the target device, and the newly connected target device on the device bus is scanned. After scanning the new target device, resources are allocated to it and link training is performed to obtain its corresponding initialization code. The initialization code is run in the first memory space to obtain the running code, and then the running code is copied to the second memory space for storage through the swap-in and swap-out module called by the interrupt service. The above steps are repeated until the initialization loading of each device is completed.
[0128] In this embodiment, the specific process of calling the target device can be found in Figure 3 , Figure 3 This is a flowchart of a target device call provided by an embodiment of the present application, as shown in the figure:
[0129] First, the swap-in / swap-out module is called through the interrupt service, and then the swap-in / swap-out module queries the storage location of the corresponding swap-in / swap-out module in the second memory space according to the information of the called target device. The swap-in / swap-out module called by the interrupt service copies the running code at the corresponding location, and then when moving the running code, the swap-in / swap-out module switches from the second working mode to the first working mode, and queries the location of the first memory space corresponding to the running code, and copies the copied running code of the target device to the corresponding location in its first memory space. Execute the running code to complete the calling command of the target device, and after the execution is completed, release the memory space occupied by the running code.
[0130] Based on the same design concept, an embodiment of the present application provides a device driver loading apparatus. Figure 4 , Figure 4 1 is a structural block diagram of a device driver loading apparatus provided by an embodiment of the present application. Figure 4 As shown, the device comprises:
[0131] An initialization code loading module, used to load the initialization code of the target device into the first memory space during the process of initializing the target device for the first time;
[0132] An initialization code running module, used to run the initialization code of the target device for the first time in the first memory space to obtain the running code of the target device;
[0133] a swap-in / swap-out module, configured to cache the running code of the target device to a second memory space, wherein the storage space size of the second memory space is larger than the storage space of the first memory space; and when a call to the target device is detected, obtain the running code of the target device from the second memory space;
[0134] The execution code execution module is used to execute the execution code of the target device in the first memory space.
[0135] Optionally, the initialization code loading module includes:
[0136] An initialization code determination submodule, used to determine the size of the initialization code of the target device during the process of initializing the target device for the first time;
[0137] The first memory space allocation submodule is used to allocate a memory space of a corresponding size in the first memory space according to the size of the initialization code of the target device and to run the initialization code of the target device.
[0138] Optionally, the swap-in and swap-out module includes:
[0139] The system memory space allocation submodule is used to allocate a memory space greater than the first threshold from the system memory space as the second memory space.
[0140] Optionally, the swap-in / swap-out module further includes:
[0141] The running code estimation submodule is used to estimate the size of the running code of each of the multiple target devices to be connected;
[0142] The system memory space allocation submodule is used to allocate a memory space larger than the first threshold and larger than the sum of the sizes of the running codes of the multiple target devices from the system memory space as the second memory space.
[0143] Optionally, the initialization code execution module includes:
[0144] The initialization code release submodule is used to release the memory space occupied by the initialization code of the target device from the first memory space.
[0145] Optionally, the initialization code loading module further includes:
[0146] A first working mode switching submodule, used for switching from the default working mode to the first working mode;
[0147] The second working mode switching submodule is used to switch from the first working mode to the second working mode.
[0148] Optionally, the swap-in / swap-out module further includes:
[0149] a swap-out submodule, used to copy the running code of the target device to the second memory space through interrupt service, and record the storage position of the running code in the first memory space and the storage position in the second memory space;
[0150] A storage location query submodule, used to query the storage location of the running code of the target device in the first memory space and the storage location in the second memory space according to the called target device;
[0151] The swap-in submodule is used to copy the running code of the target device to the storage location in the first memory space according to the storage location in the second memory space.
[0152] A third aspect of an embodiment of the present application provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, a device driver loading method as in the first aspect of an embodiment of the present application is implemented.
[0153] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the device driver loading method of the first aspect of the embodiment of the present application is implemented.
[0154] Through the device driver loading method of the embodiment of the present application, during the first initialization of the target device, the initialization code of the target device is loaded into the first memory space; the initialization code of the target device is run for the first time in the first memory space to obtain the running code of the target device; the running code of the target device is cached to the second memory space, and the storage space size of the second memory space is larger than the storage space of the first memory space; when a call to the target device is detected, the running code of the target device is obtained from the second memory space; and the running code of the target device is run in the first memory space.
[0155] Based on the same design concept, another embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps in the device driver loading method described in any of the above embodiments of the present application are implemented.
[0156] Based on the same design concept, another embodiment of the present application provides an electronic device, such as Figure 5 shown. Figure 5This is a schematic diagram of an electronic device shown in an embodiment of the present application. The electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes, the steps in the device driver loading method described in any of the above embodiments of the present application are implemented.
[0157] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0158] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0159] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present application may adopt the form of complete hardware embodiments, complete software embodiments, or embodiments in combination with software and hardware. Moreover, the embodiments of the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0160] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0161] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0162] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0163] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.
[0164] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used 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. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0165] The above is a detailed introduction to a device driver loading method, apparatus, device and medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A device driver loading method, characterized in that: include: During the first initialization of the target device, loading the initialization code of the target device into the first memory space; Running the initialization code of the target device for the first time in the first memory space to obtain the running code of the target device; caching the running code of the target device into a second memory space, wherein the storage space size of the second memory space is larger than the storage space of the first memory space; When a call to the target device is detected, obtaining the running code of the target device from the second memory space; The execution code of the target device is executed in the first memory space.
2. A device driver loading method according to claim 1, characterized in that: In the process of initializing the target device for the first time, loading the initialization code of the target device into the first memory space includes: During the first initialization of the target device, determining the size of the initialization code of the target device; In the first memory space, according to the size of the initialization code of the target device, a memory space of a corresponding size is allocated and the initialization code of the target device is executed.
3. A device driver loading method according to claim 1, characterized in that: The first memory space is associated with a first working mode, and the maximum memory space in the first working mode is a first threshold; The method further comprises: A memory space greater than the first threshold is allocated from the system memory space as the second memory space.
4. A device driver loading method according to claim 1, characterized in that: The first memory space is associated with a first working mode, and the maximum memory space in the first working mode is a first threshold; The method further comprises: Estimate the size of the running code of each of the multiple target devices to be connected; A memory space that is larger than the first threshold and larger than the sum of sizes of the respective running codes of the plurality of target devices is allocated from the system memory space as the second memory space.
5. A device driver loading method according to claim 1, characterized in that: After obtaining the running code of the target device, the method further includes: The memory space occupied by the initialization code of the target device is released from the first memory space.
6. A device driver loading method according to claim 1, characterized in that: The first memory space is associated with a first working mode, the second memory space is associated with a second working mode, and the second working mode is a default working mode; Before loading the initialization code of the target device, it also includes: Switching from the default working mode to the first working mode; In the first working mode, the steps are performed: in the process of initializing the target device for the first time, loading the initialization code of the target device in the first memory space; running the initialization code of the target device for the first time in the first memory space to obtain the running code of the target device; Switching from the first working mode to the second working mode; In the second working mode, the steps of: caching the running code of the target device to a second memory space, wherein the storage space size of the second memory space is larger than the storage space of the first memory space; when a call to the target device is detected, obtaining the running code of the target device from the second memory space; Switching from the second working mode to the first working mode; In the first working mode, the step of executing: running the running code of the target device in the first memory space.
7. A device driver loading method according to claim 1, characterized in that: Caching the running code of the target device into a second memory space includes: By interrupting the service, copying the running code of the target device to the second memory space, and recording the storage location of the running code in the first memory space and the storage location in the second memory space; When a call to a target device is detected, obtaining the running code of the target device from the second memory space includes: According to the called target device, query the storage location of the running code of the target device in the first memory space and the storage location in the second memory space; The running code of the target device will be copied to the storage location in the first memory space according to the storage location in the second memory space.
8. A device driver loading apparatus, characterized in that: The device comprises: An initialization code loading module, used to load the initialization code of the target device into the first memory space during the process of initializing the target device for the first time; An initialization code running module, used to run the initialization code of the target device for the first time in the first memory space to obtain the running code of the target device; a swap-in / swap-out module, configured to cache the running code of the target device to a second memory space, wherein the storage space size of the second memory space is larger than the storage space of the first memory space; and when a call to the target device is detected, obtain the running code of the target device from the second memory space; The execution code execution module is used to execute the execution code of the target device in the first memory space.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the computer program is executed by the processor, the device driver loading method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the device driver loading method according to any one of claims 1 to 7 is implemented.