Method, device and medium for accessing base address register space of a device
By configuring the template class to encapsulate the base address register space address and operator overloading function of the device, the problem that the traditional method cannot access the base address register space of mappable devices and unmappable devices at the same time is solved, a unified access method is realized, and development is improved. Efficiency and code maintainability.
Patent Information
- Application Number
- CN202410813567.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2044-06-21
AI Technical Summary
The traditional method cannot simultaneously access the base address register space of mappable devices and non-mappable devices through the dereference operator, resulting in low development efficiency and difficulty in code maintenance.
Configure the template class to encapsulate the base address register space address of the device, including type-related member variables and operator overloaded functions, access the virtual address of the mappable device through the dereference operator overloaded function, and access the interface functions of the unmappable device through other member variables , unified access to both.
It improves the access efficiency to the base address register space of mappable devices and non-mappable devices, simplifies the code, avoids using different access methods for different device types, and improves development efficiency and code maintainability.
Smart Images

Figure CN118409982B
Abstract
Description
Technical Field
[0001] Embodiments of the present invention generally relate to the field of computer technology, and more particularly to a method, a computing device, and a storage medium for accessing a base address register space of a device. Background Art
[0002] Generally, the base address register (BAR) space of a mappable device can be accessed through the dereference operator. Specifically, the pointer variable storing the virtual address can be operated through the dereference operator to read and write data in the BAR space of the mappable device.
[0003] However, for unmappable devices, since the base address register space of these devices cannot be mapped to the host (such as the CPU) virtual address space, there is no pointer variable to store the virtual address, and therefore it is impossible to read and write data in the BAR space of the unmappable device by means of the dereference operator.
[0004] In summary, the disadvantage of the conventional base address register space for accessing devices is that it is not possible to access both mappable devices and non-mappable devices by only performing a dereference operator operation. Summary of the invention
[0005] In response to the above problems, the present invention provides a method, a computing device and a storage medium for accessing the base address register space of a device, which can access the BAR space of both mappable devices and non-mappable devices by means of dereference operator operations, thereby improving development efficiency and making the code easy to maintain.
[0006] According to a first aspect of the present invention, there is provided a method for accessing a base address register space of a device, comprising: configuring a first template class for encapsulating data related to an address of a base address register space of the device, wherein the first template class comprises: a first member variable, the value of which is related to the type of the device, and a dereference operator overload function; in response to performing a dereference operator operation on an object defined based on the first template class, calling the dereference operator overload function in the first template class to access the base address register space of the device based at least on the first member variable and the return value of the dereference operator overload function.
[0007] In some embodiments, configuring the first template class further includes: when the device is a mappable device, making the first member variable indicate the virtual address of the base address register space address of the device after mapping; when the device is an unmappable device, making the first member variable a null pointer.
[0008] In some embodiments, the first template class further includes: an addition operator overload function. In this embodiment, the method of the first aspect of the present invention further includes: in response to performing an addition operator operation on an object defined based on the first template class, calling the addition operator overload function in the first template class to increase an offset on the base address register space address of the device based on at least the first member variable.
[0009] In some embodiments, the method of the first aspect of the present invention further includes: configuring a second template class to represent the type of the return value of the dereference operator overload function. In this embodiment, calling the dereference operator overload function in the first template class to access the base address register space of the device based on at least the first member variable and the return value of the dereference operator overload function includes: calling the dereference operator overload function in the first template class to obtain a return value of the type of the second template class; and performing a predetermined operator operation on the return value to access data in the base address register space of the device.
[0010] In some embodiments, the second template class includes: a type conversion operator overload function or an assignment operator overload function.
[0011] In some embodiments, performing a predetermined operator operation on the return value to access data in the base address register space of the device includes:
[0012] Perform type conversion operator operation on the return value to read the data in the base address register space of the device by calling the type conversion operator overload function; or
[0013] The assignment operator operation is performed on the return value so that data can be written to the base address register space of the device by calling the assignment operator overload function.
[0014] In some embodiments, the first template class further includes: a second member variable for indicating a base address register space number of the device; and a third member variable for indicating a byte offset within the base address register space of the device.
[0015] In some embodiments, the first template class further includes: a fourth member variable, used to indicate the number of the device.
[0016] In some embodiments, the first template class and the second template class have the same plurality of member variables and template parameters, and the template parameters represent the type of data stored at the address of the base address register space of the device.
[0017] In some embodiments, accessing the base address register space of the device based at least on a first member variable and the return value of a dereference operator overloaded function includes: determining the type of the device based on the first member variable; in response to the determined type of the device being a mappable device, obtaining the virtual address included in the first member variable through a dereference operator to access data in the base address register space of the device; and in response to the determined type of the device being an unmappable device, obtaining at least other member variables except the first member variable through a dereference operator to access data in the base address register space of the device.
[0018] According to a second aspect of the present invention, a computing device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor so that the at least one processor can execute the method of the first aspect of the present invention.
[0019] According to a third aspect of the present invention, there is provided a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to execute the method of the first aspect of the present invention.
[0020] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The above and other features, advantages and aspects of the embodiments of the present invention will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements.
[0022] Figure 1 A flow chart of a method for accessing a BAR space of a device according to an embodiment of the present invention is shown.
[0023] Figure 2 A flowchart of a method for calling a dereference operator overload function in a first template class according to an embodiment of the present invention is shown.
[0024] Figure 3 A block diagram of a computing device suitable for implementing embodiments of the present invention is schematically shown. DETAILED DESCRIPTION
[0025] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0026] As used herein, the term "including" and its variations mean open inclusion, i.e., "including but not limited to". Unless otherwise stated, the term "or" means "and / or". The term "based on" means "based at least in part on". The terms "an example embodiment" and "an embodiment" mean "at least one example embodiment". The term "another embodiment" means "at least one additional embodiment". The terms "first", "second", etc. may refer to different or the same objects. Other explicit and implicit definitions may also be included below.
[0027] Generally, for devices such as real PCI (Peripheral Component Interconnect) devices that can map the base address register (BAR) space of the device to the virtual address space of the host (i.e., CPU) through address mapping technology, also known as "mappable devices", access to these mappable devices can be achieved by accessing the virtual address in the virtual address space of the host. Specifically, the address mapping technology can be used to map the address interval on the BAR space of PCI devices or simulated PCI devices based on virtualization technology to the address interval on the CPU virtual address space, and the virtual address in the virtual address interval can be stored in a pointer variable, so that the pointer variable can be operated through the dereference operator, thereby realizing the reading and writing of data in the BAR space of the mappable device.
[0028] For those devices whose BAR space cannot be mapped to the CPU virtual address space, also known as "unmappable devices", it is necessary to call the interface function configured on the device specifically for accessing its BAR space to access the BAR space of these unmappable devices. In other words, data can be read and written to the BAR space of unmappable devices by calling the interface function of unmappable devices.
[0029] In summary, when the CPU accesses the BAR space of a device, for a mappable device, the BAR space of the device can be read and written by the dereference operator; for a non-mappable device, the BAR space of the device needs to be read and written by calling an interface function. In other words, in the traditional scheme for accessing the base address register space of a device: different methods are required to access the BAR space of both mappable and non-mappable devices.
[0030] However, since the methods of accessing the BAR space of mappable devices and non-mappable devices are different, especially, as mentioned above, only the BAR space of mappable devices can be accessed through the dereference operator operation, while the BAR space of non-mappable devices cannot be accessed. Therefore, when accessing the BAR space of different devices based on C++ programs, developers need to use different codes for mappable devices and non-mappable devices, which reduces development efficiency and increases code maintenance work.
[0031] In order to at least partially solve the above-mentioned problems and one or more of other potential problems, an example embodiment of the present invention proposes a scheme for accessing the base address register space of a device, by configuring a first template class to encapsulate relevant data of the base address register space address of the device, wherein the first template class includes: a first member variable, whose value is related to the type of the device, and a dereference operator overload function; in response to a dereference operator operation on an object defined based on the first template class, the dereference operator overload function in the first template class is called to access the base address register space of the device based on at least the first member variable, so that the base address register space of both mappable devices and non-mappable devices can be accessed by means of dereference operator operation, thereby improving development efficiency and making the code easy to maintain.
[0032] The following will be combined Figure 1 to Figure 2 A scheme for accessing the base address register space of a device according to the present invention is described in detail. Figure 1 A flowchart of a method 100 for accessing a BAR space of a device according to an embodiment of the present invention is shown. It should be understood that the method 100 may also include additional actions not shown and / or may omit the actions shown, and the scope of the present invention is not limited in this respect.
[0033] In step 101, a first template class is configured to encapsulate data related to a BAR space address of a device.
[0034] The first template class may be used to represent data related to a certain address in the BAR space of the device. For example, the first template class may describe an address in the BAR space of the device. According to an embodiment of the present invention, the first template class may at least include: a dereference operator overload function and a first member variable, wherein the value of the first member variable is related to the type of the device.
[0035] Regarding the type of device, as mentioned above, the devices involved in the present invention can be divided into mappable devices and non-mappable devices, which will not be described in detail here.
[0036] Regarding the first member variable, in an embodiment of the present invention, the value of the first member variable can be determined based on the type of device. Specifically, when the device is a mappable device, since the BAR space of these devices can be mapped to the virtual address space of the CPU through address mapping technology, the first member variable can indicate the virtual address of the BAR space address of the device after mapping; when the device is an unmappable device, since the BAR space of these devices cannot be mapped to the virtual address space of the CPU, the first member variable is made a null pointer (null). That is to say, for a mappable device, the value of the first member variable in its first template class is related to the virtual address after mapping; and for an unmappable device, the value of the first member variable in its first template class is a null pointer. In some other embodiments, the first member variable may refer to the return value of a member function included in the first template class. In other words, the return value of the member function can be regarded as a member variable.
[0037] According to an embodiment of the present invention, the first template class may further include a template parameter for indicating the type of data stored at the address of the base address register space of the device. For example, the template parameter may be an integer (int) type.
[0038] Related data about the BAR space address of the device, which may include data such as the BAR space number of the device, the byte offset within the BAR space, the device number, etc.
[0039] Regarding the dereference operator overload function, it can be used to describe the behavior in response to the dereference operator operation on the object of the first template class.
[0040] According to an embodiment of the present invention, the first template class may further include a plurality of member variables for indicating data related to the BAR space address of the device respectively. In some embodiments, the first template class may include: a second member variable for indicating the BAR space number of the device; and a third member variable for indicating the byte offset within the BAR space of the device. In some further embodiments, when multiple devices are included, the first template class may further include: a fourth member variable for indicating the number of the device. That is, the device to which the BAR space to be accessed belongs may be indicated by the fourth member variable.
[0041] In step 102, a dereference operator operation is performed on an object defined based on the first template class to call a dereference operator overload function in the first template class to access the BAR space of the device based on at least the first member variable and the first return value of the dereference operator overload function. Figure 2 Describe in detail how to call the dereference operator overload function in the first template class.
[0042] Further, according to an embodiment of the present invention, accessing the BAR space of a device based at least on a first member variable and a first return value of a dereference operator overloaded function may include: determining the type of the device based on the first member variable; in response to determining that the device is a mappable device, obtaining the virtual address included in the first member variable through a dereference operator to access data in the base address register space of the device; and in response to determining that the device is an unmappable device, obtaining at least other member variables except the first member variable through a dereference operator to access data in the base address register space of the device.
[0043] Regarding determining the type of the device according to the first member variable, it can be determined by judging whether the first member variable is a null pointer. If the first member variable is a null pointer, the device is determined to be an unmappable device; if the first member variable is not a null pointer, the device is determined to be a mappable device.
[0044] As described above, to access the BAR space of an unmappable device, it is necessary to call an interface function configured on the device that is specifically used to access its BAR space. Generally, the interface function may include the following parameters: device number, device BAR space number, byte offset within the device BAR space, and number of bytes to read (or number of bytes to write). Since the information indicated by the member variables of the first template class of the present invention coincides with the information expressed by the parameters included in the interface function, the values of the parameters of the interface function can be obtained from the member variables to implement the function of calling the interface function to access the BAR space of an unmappable device at least based on the first template class.
[0045] For example, in an embodiment of the present invention, in response to the determined type of the device being a mappable device, the data in the base address register space of the device can be accessed by accessing the return value of the dereference operator operation on the first member variable, that is, the data in the address described by the object defined based on the first template class; in response to the determined type of the device being an unmappable device, other member variables except the first member variable can be obtained through the dereference operator, and the parameters required by the interface function of the unmappable device can be obtained based on these other member variables, and then the data in the base address register space of the device can be accessed by calling the interface function.
[0046] In summary, the present invention configures a first template class that encapsulates data related to the BAR space address of the device, and makes the first template class include: a dereference operator overload function, and a member variable indicating data related to the device and its BAR space address, so that when a dereference operator operation is performed on an object defined based on the first template class, the BAR space of the device including the unmappable device can be accessed by calling the dereference operator overload function. In other words, the present invention can access the address described by the object of the first template class, that is, the BAR space of the device, by accessing the return value of the dereference operator operation performed on the object of the first template class. Therefore, the present invention can implement access to the BAR space of both mappable devices and unmappable devices by means of dereference operator operation, avoiding developers from using different codes for mappable devices and unmappable devices, improving development efficiency, and making the code easy to maintain.
[0047] Figure 2 A flowchart of a method 200 for calling a dereference operator overload function in a first template class according to an embodiment of the present invention is shown. It should be understood that method 200 may also include additional actions not shown and / or may omit the actions shown, and the scope of the present invention is not limited in this respect.
[0048] In step 201, a second template class is configured to represent the type of the return value of the dereference operator overload function.
[0049] Regarding the second template class, it may include the same member variables and template parameters as those in the first template class. According to an embodiment of the present invention, the second template class may include multiple member variables indicating data related to the BAR space address of the device, such as a member variable related to the type of device, a member variable indicating the BAR space number of the device, a member variable indicating the byte offset within the BAR space of the device, a member variable indicating the number of the device, and the like. Furthermore, the value of each member variable in the second template class is the same as the value of the corresponding member variable in the first template class. For example, when the value of the fourth member variable indicating the number of the device in the first template class is 3, the value of the member variable indicating the number of the device in the second template class is also 3.
[0050] Furthermore, the second template class may also include a member function so that when the member function is called, access to the BAR space of the device is implemented. According to some embodiments of the present invention, the second template class may include a type conversion operator overload function, wherein the type conversion operator overload function may be used to describe the behavior in response to performing a type conversion operator operation on an object of the second template class, so that when the type conversion operator overload function is called, data in the BAR space of the device may be read. According to some further embodiments of the present invention, the second template class may include an assignment operator overload function, wherein the assignment operator overload function may be used to describe the behavior in response to performing an assignment operator operation on an object of the second template class, so that when the assignment operator overload function is called, data may be written to the BAR space of the device. How to call the member function in the second template class will be described in detail in step 203 below, which will not be repeated here.
[0051] Regarding access to the BAR space of the device, according to an embodiment of the present invention, it includes read access and write access.
[0052] In step 202, the dereference operator overload function in the first template class is called to obtain a return value of the second template class type.
[0053] Furthermore, in an embodiment of the present invention, since the second template class includes member variables that are the same as those of the first template class, the return value of the second template class type can include relevant data indicating the BAR space address of the device, and thus the data of the BAR space of the device can be accessed based on the return value.
[0054] In step 203, a predetermined operator operation is performed on the return value to access data in the BAR space of the device.
[0055] Regarding the predetermined operator operation, it may be determined by the access method to the BAR space of the device. According to an embodiment of the present invention, if data of the BAR space of the device is to be read, the predetermined operator operation may be a type conversion operator operation; if data is to be written to the BAR space of the device, the predetermined operator operation may be an assignment operator operation.
[0056] Specifically, when the predetermined operator operation is a type conversion operator operation, the type conversion operator overload function is called, and then the data in the BAR space of the device can be read by executing the type conversion operator overload function. In one example, when the operator " " appears on the right side of the operator "=", the type conversion operator overload function will be called.
[0057] For example, suppose the variable a For example, integer (int) type, variable p is an object defined based on the first template class, then for
[0058]
[0059] When the operator " "Action on variables p When the return type is the return value of the second template class, the return value can be regarded as an object of the second template type, and then the type conversion operator acts on the return value, so that the type conversion operator overload function of the second template class is called.
[0060] In this example, for a mappable device, the operator " " acts on the member variable in the second template class corresponding to the first member variable m_va of the first template class to realize reading data from the BAR space address of the mappable device; for the unmappable device, the member variables corresponding to the second member variable m_barId, the third member variable m_barOffset and the fourth member variable m_devId of the first template class can be obtained from the second template class to obtain the parameters of the interface function used by the unmappable device to read the BAR space, and call the interface function to realize reading data from the BAR space address of the unmappable device.
[0061] Accordingly, when the predetermined operator operation is an assignment operator operation, the assignment operator overload function is called, and then the data can be written to the BAR space of the device by executing the assignment operator overload function. For example, in one example, when the operator " " appears on the left side of the "=" operator, the assignment operator overload function will be called.
[0062] For example, assuming that the variable aFor example, integer (int) type, variable p is an object defined based on the first template class, then for
[0063]
[0064] When the operator " "Action on variables p When the return type is the return value of the second template class, the return value can be regarded as an object of the second template type, and then the assignment operator acts on the return value, so that the assignment operator overload function of the second template class is called.
[0065] In this example, for a mappable device, the operator " " acts on the member variable in the second template class corresponding to the first member variable m_va of the first template class, so as to realize writing data to the BAR space address of the mappable device; for the unmappable device, the member variables corresponding to the second member variable m_barId, the third member variable m_barOffset and the fourth member variable m_devId of the first template class can be obtained from the second template class, so as to obtain the parameters of the interface function used by the unmappable device to read the BAR space, thereby realizing writing data to the BAR space address of the unmappable device.
[0066] The following is an exemplary code of the first template class and the second template class according to an embodiment of the present invention. It should be understood that the following description and the codes involved therein are for illustrative purposes only and are not restrictive.
[0067] For example, you can configure the first template class VA <t>, to represent data related to a certain address in the BAR space of a PCI device, where the template parameter T represents the type of data stored at the address, such as an integer (int). The following shows the first template class VA configured in one embodiment of the present invention: <t>Example code for .
[0068]
[0069] As shown in the above code, the first template class VA <t>Includes multiple member variables. Specifically, the first template class VA <t>It includes: a first member variable m_va; a second member variable m_barId indicating the BAR space number of the device; a third member variable m_barOffset indicating the byte offset within the BAR space of the device; and a fourth member variable m_devId indicating the number of the device. Among them, the data type of the first member variable m_va is That is, for the first member variable m_va, the data pointed to by the pointer is of type T. The second member variable m_barId, the third member variable m_barOffset and the fourth member variable m_devId are all of type int.
[0070] Furthermore, the first member variable m_va can be used to record the virtual address corresponding to the BAR space address of the mappable device after mapping. However, for a non-mappable device, its first member variable m_va can be assigned a null pointer.
[0071] As shown in the above code, the first template class VA <t>It also includes member functions. According to the concept of the present invention, in order to make the dereference operator " "Acts on the first template class VA <t>When defining an object, it can achieve the same operation effect as acting on a pointer variable. The first template class VA <t>You can include a dereference operator overload as a member function so that when the dereference operator " "Acts on the first template class VA <t>When defining an object, you can call the first template class VA <t>The dereference operator is overloaded in the function.
[0072] Furthermore, the second template class VA_DATA can be configured <t>, used to represent the type of the return value of the dereference operator overload function. The following shows the second template class VA_DATA configured in one embodiment of the present invention <t>Example code for .
[0073]
[0074] As shown in the above code, the second template class VA_DATA <t>With the first template class VA <t>Have the same multiple member variables and template parameters T. Specifically, the second template class VA_DATA <t>The member variables of the second template class VA_DATA include: m_va, m_barId, m_barOffset, m_devId. Further, according to an embodiment of the present invention, the second template class VA_DATA <t>The values of each member variable of the first template class VA <t>The values of the member variables of the second template class VA_DATA are the same. <t>The value of the member variable m_va is the same as the value of the first template class VA <t>The value of the first member variable m_va is the same as the value of the second template class VA_DATA <t>The value of the member variable m_barId is the same as the value of the first template class VA <t>The value of the second member variable m_barId is the same as the value of the second template class VA_DATA <t>The value of the member variable m_barOffset is the same as the value of the first template class VA <t>The value of the third member variable m_barOffset is the same as that of the second template class VA_DATA <t>The value of the member variable m_devId is the same as the value of the first template class VA <t>The same value as the fourth member variable m_devId.
[0075] In summary, the present invention configures the first template class and the second template class so that the BAR space of both the mappable device and the non-mappable device can be accessed by means of the dereference operator operation, thereby improving development efficiency and making the code easy to maintain.
[0076] Furthermore, according to the inventive concept of the present invention, the addition operator operation can also be performed on the object defined based on the first template class, so that when the addition operator ("+") is applied to the object defined based on the first template class, the same operation effect as that applied to the pointer variable can be achieved.
[0077] According to an embodiment of the present invention, the first template class may further include an addition operator overload function as a member function, wherein the addition operator overload function may be used to describe a behavior in response to performing an addition operator operation on an object of the first template class. In this case, in response to performing an addition operator operation on an object defined based on the first template class, the addition operator overload function in the first template class may be called to increase an offset on a BAR space address of the device based on at least the first member variable.
[0078] Specifically, when the addition operator "+" is applied to an object defined based on the first template class, the addition operator overload function of the first template class is called and returns a return value of the same type as the first template class, wherein the value of the third member variable indicating the byte offset within the BAR space of the device in the return value is the updated value after the offset is increased, and the values of other member variables in the return value remain unchanged.
[0079] For example, suppose the variable a For example, integer (int) type, variable p is an object defined based on the first template class, then for
[0080] p + a
[0081] It can represent a new variable of the first template class type (denoted as l, where l = p + a), and the variable l The BAR space address of the device represented by the variable p The BAR space address of the indicated device plus an offset, which is a variable a Multiply by the number of bytes occupied by the int type.
[0082] Therefore, by further including the addition operator overload function as a member function in the first template class, it is possible to increase the offset of the BAR space address of both mappable devices and non-mappable devices through the addition operator operation, thereby improving development efficiency and making the code easy to maintain.
[0083] Figure 3 The block diagram of a computing device 300 suitable for implementing an embodiment of the present invention is schematically shown. The device 300 may be a computer system for implementing an embodiment of the present invention. Figure 1 The method 100 shown, and Figure 2 The method 200 is shown in the apparatus. Figure 3 As shown, the device 300 includes a central processing unit (CPU) 301, which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) 302 or loaded from a storage unit 308 to a random access memory (RAM) 303. In the RAM 303, various programs and data required for the operation of the device 300 can also be stored. The CPU 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.
[0084] Multiple components in the device 300 are connected to the I / O interface 305, including: an input unit 306, an output unit 307, and a storage unit 308. The processing unit 301 performs the various methods and processes described above, such as performing method 100 or method 200. For example, in some embodiments, method 100 or method 200 may be implemented as a computer software program, which is stored in a machine-readable medium, such as storage unit 308. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 300 via ROM 302 and / or communication unit 309. When the computer program is loaded into RAM 303 and executed by CPU 301, one or more operations of method 100 or method 200 described above may be performed. Alternatively, in other embodiments, CPU 301 may be configured to perform one or more actions of method 100 and / or method 200 in any other appropriate manner (e.g., by means of firmware).
[0085] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0086] The computer program instructions for performing the operation of the present invention may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The computer-readable program instructions may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect through the Internet). In some embodiments, by using the state information of the computer-readable program instructions to personalize an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA) or a programmable logic array (PLA), the electronic circuit may execute the computer-readable program instructions, thereby implementing various aspects of the present invention.
[0087] These computer-readable program instructions can be provided to a processor in a voice interaction device, a general-purpose computer, a special-purpose computer, or a processing unit of other programmable data processing devices, thereby producing a machine, so that when these instructions are executed by the processing unit of a computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other device to work in a specific manner.
[0088] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
[0089] The above are only optional embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.< / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t> < / t>
Claims
1. A method for accessing a base address register space of a device, characterized in that: include: A first template class is configured to encapsulate data related to a base address register space address of the device, wherein the first template class includes: a first member variable, the value of which is related to the type of the device; The second member variable is used to indicate the base address register space number of the device. a third member variable indicating a byte offset within the base address register space of the device, and Dereference operator overloaded function; In response to performing a dereference operator operation on an object defined based on the first template class, calling the dereference operator overload function in the first template class to access a base address register space of the device based on at least the first member variable and a return value of the dereference operator overload function, Wherein, accessing the base address register space of the device based at least on the first member variable and the return value of the dereference operator overload function comprises: Determining the type of the device according to the first member variable; and In response to the determination that the type of the device is an unmappable device, other member variables except the first member variable are obtained at least through a dereference operator to access data in a base address register space of the device.
2. The method according to claim 1, characterized in that Configuring the first template class also includes: When the device is a mappable device, the first member variable indicates a virtual address of the base address register space address of the device after being mapped; When the device is an unmappable device, the first member variable is set to a null pointer.
3. The method according to claim 1, characterized in that: The first template class also includes: an addition operator overload function; The method further comprises: In response to performing an addition operator operation on an object defined based on the first template class, the addition operator overload function in the first template class is called to increase an offset on a base address register space address of the device based on at least the first member variable.
4. The method according to claim 1, characterized in that The method further comprises: configuring a second template class to represent the type of the return value of the dereference operator overload function; and Calling the dereference operator overload function in the first template class to access the base address register space of the device based on at least the first member variable and the return value of the dereference operator overload function comprises: Calling the dereference operator overloaded function in the first template class to obtain a return value of the type of the second template class; and A predetermined operator operation is performed on the return value to access data in the base address register space of the device.
5. The method according to claim 4, characterized in that The second template class includes: at least one of a type conversion operator overloading function and an assignment operator overloading function.
6. The method according to claim 5, characterized in that Performing a predetermined operator operation on the return value to access data in the base address register space of the device includes: Performing a type conversion operator operation on the return value, so as to read data in the base address register space of the device by calling the type conversion operator overload function; or An assignment operator operation is performed on the return value so as to write data into the base address register space of the device by calling the assignment operator overload function.
7. The method according to claim 1, characterized in that The first template class also includes: The fourth member variable is used to indicate the serial number of the device.
8. The method according to claim 4, characterized in that The first template class and the second template class have the same plurality of member variables and template parameters, and the template parameters represent the type of data stored at the base address register space address of the device.
9. The method according to claim 4, characterized in that Accessing the base address register space of the device based at least on the first member variable and the return value of the dereference operator overload function further comprises: In response to the determination that the type of the device is a mappable device, the virtual address contained in the first member variable is operated by a dereference operator to access data in a base address register space of the device.
10. A computing device comprising: at least one processor; as well as a memory communicatively coupled to the at least one processor; The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method according to any one of claims 1 to 9.
11. A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to execute the method of any one of claims 1 to 9.
