Direct memory access controller, electronic device using the same, and method for operating the same
By introducing mode registers and control circuits in the direct memory access controller, DMA operation switching between safe and non-safe modes is realized, solving the problems of waste of resources and high costs in the prior art, and providing Flexible and secure access to data.
Patent Information
- Application Number
- CN202011111422.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-16
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2040-10-16
AI Technical Summary
Existing systems require independent DMA controllers or DMA channels when switching between secure and non-secure modes, resulting in waste of resources and increased costs.
A direct memory access controller is designed, including a direct memory access channel, a mode register, a setting interface and a control circuit. The mode register switches between safe and non-safe modes to realize a single circuit. or DMA operation of hardware.
A flexible switching between secure and non-secure modes is achieved, saving hardware resources, reducing costs, and providing security mechanisms to protect sensitive data.
Smart Images

Figure CN114385528B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a direct memory access (DMA) controller, and more particularly to a shared DMA controller and a method for operating the DMA controller. Background Art
[0002] For security reasons, electronic devices usually store confidential or sensitive data in a secure area (also called secure memory) in the memory, and store non-confidential or non-sensitive data in a non-secure area (also called non-secure memory) in the memory. Therefore, a system on a chip (SoC) that can operate in secure mode and non-secure mode usually uses independent DMA controllers or independent DMA channels for the two modes. However, since the DMA controller or DMA channel is not always used by the same security level (i.e., secure mode or non-secure mode), this approach is more resource-intensive. Summary of the invention
[0003] In view of the deficiencies of the prior art, an object of the present invention is to provide a direct memory access controller, an electronic device using the direct memory access controller, and a method for operating the direct memory access controller.
[0004] The present invention discloses a direct memory access controller for accessing a memory, wherein the memory includes a secure area and a non-secure area. The direct memory access controller includes a direct memory access channel, a mode register, a setting interface and a control circuit. The mode register is used to store a temporary value. When the temporary value is a first value, the direct memory access channel operates in a secure mode, and when the temporary value is a second value, the direct memory access channel operates in a non-secure mode. The setting interface is used to receive a control command. The control circuit is coupled to the direct memory access channel and is used to set the temporary value of the mode register according to the control command. When the direct memory access channel operates in the secure mode, the direct memory access channel can access the secure area and the non-secure area, and when the direct memory access channel operates in the non-secure mode, the direct memory access channel can access the non-secure area but cannot access the secure area.
[0005] The present invention further discloses an electronic device, comprising a processor, a memory and a direct memory access controller. The processor is used to generate a control command, and the control command is used to set an operation mode of the direct memory access controller. The memory includes a secure area and a non-secure area. The direct memory access controller couples the processor and the memory via a bus, and comprises a direct memory access channel, a setting interface and a mode register. The direct memory access controller receives the control command via the setting interface. The mode register is used to store a temporary value corresponding to the control command. When the temporary value is a first value, the direct memory access channel operates in a secure mode, and when the temporary value is a second value, the direct memory access channel operates in a non-secure mode. When the direct memory access channel operates in the secure mode, the direct memory access channel can access the secure area and the non-secure area, and when the direct memory access channel operates in the non-secure mode, the direct memory access channel can access the non-secure area but cannot access the secure area.
[0006] The present invention also discloses a method for operating a direct memory access controller. The direct memory access controller is used to access a memory, and the memory includes a secure area and a non-secure area. The method includes: finding a direct memory access channel in an idle state in the direct memory access controller; setting a temporary value of a mode register of the direct memory access channel to make the direct memory access channel operate in a secure mode; setting an address register and a count register of the direct memory access channel; and controlling the direct memory access channel to perform data transfer based on the address register and the count register.
[0007] The DMA controller or its DMA channel of the present invention can switch between the secure mode and the non-secure mode. Compared with the conventional technology, the DMA controller or its DMA channel of the present invention can realize the DMA operation in the secure mode and the DMA operation in the non-secure mode by using a single circuit or hardware, thus saving hardware resources and reducing costs.
[0008] The features, implementation and effects of the present invention are described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] Figure 1 A functional block diagram of an embodiment of a DMA controller of the present invention;
[0010] Figure 2 A flowchart of one embodiment of a method for operating a DMA controller according to the present invention;
[0011] Figure 3AAn example of the reply content of the DMA channel 120 in response to the poll;
[0012] Figure 3B Another example of the reply content of the DMA channel 120 in response to the poll;
[0013] Figure 4 An embodiment of a selection circuit for DMA channel 120 to respond to polling; and
[0014] Figure 5 A flow chart showing one embodiment of the security mechanism of a DMA controller or DMA channel of the present invention. DETAILED DESCRIPTION
[0015] The technical terms used in the following descriptions refer to the customary terms in the technical field. If some of the terms are explained or defined in this specification, the interpretation of those terms shall be based on the explanation or definition in this specification.
[0016] The disclosure of the present invention includes a direct memory access controller, an electronic device using the direct memory access controller, and a method for operating the direct memory access controller. Since some components included in the memory access controller and the electronic device of the present invention may be known components individually, the details of the known components will be omitted in the following description without affecting the full disclosure and feasibility of the device invention.
[0017] In the following embodiments, the DMA controller includes more than two DMA channels, however, in other embodiments, the DMA controller may include only one DMA channel. When the DMA controller may include only one DMA channel, operating the DMA controller is equivalent to operating the DMA channel, and vice versa.
[0018] Figure 1 The functional block diagram of one embodiment of the DMA controller of the present invention. The DMA controller 100 includes a control circuit 110, a plurality of DMA channels 120 (including but not limited to the two DMA channels shown in the figure: DMA channel 0 (120-0) and DMA channel 1 (120-1)), a configuration interface 130 and a master interface 140. Each DMA channel 120 includes a register file 121, and each register file 121 includes a mode register 122, an address register 124 and a bytecount register 126.
[0019] The control circuit 110 may also be referred to as an arbitrator of the DMA controller 100, and may be hardware or a combination of software and hardware. When the control circuit 110 is implemented by hardware, the control circuit 110 may be a finite state machine (FSM) implemented by a logic circuit. When the control circuit 110 is a combination of hardware and software, the control circuit 110 includes a computing unit and a memory. The computing unit is a circuit or electronic component with program execution capability (e.g., a microprocessor, a microprocessing unit, a digital signal processor, or an application specific integrated circuit (ASIC)), and performs the functions of the control circuit 110 by executing program codes or program instructions stored in the memory.
[0020] The DMA channel 120 can operate in a secure mode or a non-secure mode, and the DMA channel 0 (120-0) and the DMA channel 1 (120-1) are independent of each other. For example, the DMA channel 0 (120-0) and the DMA channel 1 (120-1) can operate in a secure mode or a non-secure mode at the same time, or one can operate in a secure mode and the other can operate in a non-secure mode. When the temporary value of the mode register 122 of the DMA channel 120 is a first value (e.g., logic 1), the DMA channel 120 operates in a secure mode, and when the temporary value of the mode register 122 of the DMA channel 120 is a second value (e.g., logic 0), the DMA channel 120 operates in a non-secure mode.
[0021] When the DMA controller 100 or the DMA channel 120 is set to the safe mode, the DMA controller 100 or the DMA channel 120 operates in the safe mode, and all subsequent setting or reading operations need to be performed using the control command of the safe mode. If the control command of the non-safe mode attempts to read the DMA controller 100 or the DMA channel 120, or attempts to set the DMA controller 100 or the DMA channel 120 to move data, the DMA controller 100 operating in the safe mode or the DMA channel 120 operating in the safe mode will reject these operations. In some embodiments, when the software or hardware in the non-safe mode attempts to read the settings of the DMA controller 100 operating in the safe mode or the settings of the DMA channel 120 operating in the safe mode, the DMA controller 100 operating in the safe mode or the DMA channel 120 operating in the safe mode does not return the real value, but returns "0", a reserved value or a random value to prevent the software or hardware in the non-safe mode from knowing the settings of the DMA controller 100 operating in the safe mode or the settings of the DMA channel 120 operating in the safe mode.
[0022] The setting interface 130 and the main interface 140 are coupled to the processor 300 (e.g., a central processing unit, a microprocessor, a microprocessing unit, a digital signal processor, or an application-specific integrated circuit), the secure memory 400, and the non-secure memory 500 through the bus 200. The bus 200 can also be an interconnect or a bus matrix. The secure memory 400 and the non-secure memory 500 can be two independent physical memories (e.g., dynamic random access memory (DRAM)), or different blocks or regions of the same physical memory (i.e., secure / non-secure blocks, or secure / non-secure regions). The processor 300 transmits a control command CM through the bus 200, and the DMA controller 100 receives the control command CM through the setting interface 130. The control command CM can be used to set the temporary value of the mode register 122 of the DMA channel 120. The control command CM includes a secure attribute, and the processor 300 generates a control command CM for a secure mode or a control command CM for a non-secure mode by controlling the value of the secure attribute. More specifically, the security attribute of the control command CM generated by the processor 300 operating in the secure mode is a first logic value (eg, logic 1), while the security attribute of the control command CM generated by the processor 300 operating in the non-secure mode is a second logic value (eg, logic 0).
[0023] In some embodiments, the control circuit 110 sets the mode register 122 of the target DMA channel 120 according to the control command CM. More specifically, the control circuit 110 sets the mode register 122 of the target DMA channel 120 based on the security attribute. For example, when the security attribute of the control command CM is a first logic value (e.g., logic 1), the control circuit 110 sets the temporary value of the mode register 122 of the target DMA channel 120 to the first logic value, and when the security attribute of the control command CM is a second logic value (e.g., logic 0), the control circuit 110 sets the temporary value of the mode register 122 of the target DMA channel 120 to the second logic value. In some embodiments, the setting interface 130 may be an Advanced Peripheral Bus (APB), and the security attribute is one bit of a protection signal (Pprot) (e.g., the bit value is 1, i.e., Pprot[1]). In other embodiments, the configuration interface 130 may be an Advanced High-performance Bus (AHB) or other interfaces.
[0024] The processor 300 operating in the secure mode can read the settings made by another processor (not shown) on the DMA controller 100 or the DMA channel 120, and the other processor operates in the non-secure mode. The processor 300 operating in the secure mode can further control the behavior of the DMA controller 100 and / or the DMA channel 120. For example, when the DMA controller 100 or the DMA channel 120 is set to the secure mode, another processor in the non-secure mode cannot obtain the DMA controller 100 or the DMA channel 120 to transmit data for itself.
[0025] When the DMA channel 120 operates in the secure mode, the DMA channel 120 can access the secure memory 400 and the non-secure memory 500, and when the DMA channel 120 operates in the non-secure mode, the DMA channel 120 can access the non-secure memory 500 but cannot access the secure memory 400. More specifically, the DMA channel 120 transmits a read / write command CRW to the secure memory 400 and / or the non-secure memory 500 through the host interface 140 and the bus 200. The host interface 140 can distinguish between commands in the secure mode and commands in the non-secure mode. The read / write command CRW includes a security attribute, and the secure memory 400 determines whether to allow the read and / or write operation based on the security attribute. For example, when the DMA channel 120 operates in a secure mode, the security attribute of the read / write command CRW issued by the DMA channel 120 is a first logic value (corresponding to the secure mode), so that the secure memory 400 and the non-secure memory 500 are allowed to read and / or write operations; when the DMA channel 120 operates in a non-secure mode, the security attribute of the read / write command CRW issued by the DMA channel 120 is a second logic value (corresponding to the non-secure mode), so that the secure memory 400 is not allowed to read and / or write operations, but the non-secure memory 500 is allowed to read and / or write operations. In some embodiments, the host interface 140 can be an advanced peripheral bus, an advanced high-performance bus, or an advanced expandable interface (AXI). In some embodiments, the bus 200 determines whether the DMA controller 100 or the DMA channel 120 is allowed to access the secure memory 400.
[0026] Figure 2This is a flow chart of one embodiment of a method for operating a DMA controller of the present invention. Initially, the processor 300 operates in a safe mode (step S210) and needs to find an idle (i.e., unused) DMA controller or DMA channel (step S220). In some embodiments, the processor 300 queries the status of the DMA controller 100 or the DMA channel 120 with a query command QM, such as accessing each DMA channel 120 of the DMA controller 100 in a polling manner. In response to the polling signal, the DMA channel 120 generates a reply content RC, and the reply content RC is related to the operating mode of the processor 300 (i.e., safe mode or non-safe mode) (e.g., Figure 3A and 3B shown).
[0027] Figure 3A is the response content RC of the DMA channel 120 in response to the polling signal when the processor 300 operates in the safe mode, and Figure 3B The response content RC of the DMA channel 120 in response to the polling signal when the processor 300 operates in the non-secure mode. Figure 3A and Figure 3B In the example, assume that the current operating modes of DMA channel 0 to DMA channel 3 are non-secure mode, non-secure mode, secure mode and secure mode, respectively, and assume that the current states of DMA channel 0 to DMA channel 3 are busy, idle, idle and busy, respectively.
[0028] See also Figure 3A When the processor 300 operates in the safe mode, the reply content RC of the DMA channel 120 includes the current operation mode and the real state (i.e., idle or busy) of the DMA channel 120. The real state refers to the current state of the DMA channel 120 that has not been adjusted, modified, or changed. Therefore, the processor 300 operating in the safe mode can know the current operation mode and the real state of the DMA channel 120.
[0029] See also Figure 3B, when the processor 300 operates in the non-secure mode, the reply content RC of the DMA channel 120 includes the state but does not include the operation mode, and the state in the reply content RC is not necessarily the actual state of the DMA channel 120 at the moment. More specifically, when the DMA channel operating in the non-secure mode receives a polling signal from the processor 300 operating in the non-secure mode, the DMA channel operating in the non-secure mode replies to the current state but does not reply to the operation mode; when the DMA channel operating in the secure mode receives a polling signal from the processor 300 operating in the non-secure mode, the DMA channel operating in the secure mode always replies to "busy" and does not reply to the operation mode. In other words, although the DMA channel 2 is actually in an idle state, in order to prevent the processor 300 operating in the non-secure mode from accessing the DMA channel operating in the secure mode, the DMA channel 2 replies to a fake state or a dummy state. Therefore, the processor 300 operating in the non-secure mode can know the real state of the DMA channel operating in the non-secure mode, but cannot know the real state of the DMA channel operating in the secure mode, and the processor 300 operating in the non-secure mode cannot know the operation mode of the DMA channel. Under such a design, the processor 300 operating in the non-secure mode cannot set the DMA controller 100 operating in the secure mode or the DMA channel 120 operating in the secure mode.
[0030] In some embodiments, the processor 300 operating in non-secure mode can only query whether the DMA controller 100 or the DMA channel 120 is idle, but cannot terminate the DMA controller 100 or the DMA channel 120, or cannot make the DMA controller 100 or the DMA channel 120 leave the secure mode.
[0031] In some embodiments (such as Figure 4 ), the DMA channel 120 operating in the secure mode uses a selection circuit 600 (e.g., a multiplexer) to restore a real state or a virtual state based on the security attribute of the control command CM. When the security attribute is logic 1 (corresponding to the secure mode), the DMA channel 120 restores the real state; when the security attribute is logic 0 (corresponding to the non-secure mode), the DMA channel 120 restores the virtual state.
[0032] Back to Figure 2. When the processor 300 does not find an idle DMA controller or DMA channel (i.e., the judgment of step S220 is no), the processor 300 continues to search for an idle DMA controller or DMA channel (step S220). When the processor 300 finds an idle DMA controller or DMA channel (i.e., the judgment of step S220 is yes), the processor 300 changes the temporary value of the mode register 122 of the idle DMA channel to control the idle DMA channel to operate in a safe mode (step S230). After setting the mode register 122, the processor 300 continues to set the address register 124 and the count register 126 of the DMA channel with other control commands (step S240). For example, the processor 300 can store the address of the memory block to be read or written in the address register 124, and store the amount of data in the count register 126. Then, the DMA channel 120 issues a read / write command CRW through the host interface 140 based on the temporary value stored in the address register 124 and the temporary value stored in the count register 126 to perform data transfer (step S250 ).
[0033] After the data transfer is completed (i.e., the judgment of step S260 is yes), the DMA channel 120 sends an interrupt to notify the processor 300 that the data transfer is completed, and then the processor 300 determines whether to control the DMA channel to operate in the non-safe mode (step S270). If the processor 300 wants to continue to use the DMA channel, the processor 300 does not control the DMA channel to operate in the non-safe mode (i.e., the judgment of step S270 is no), and then continues to select the DMA channel in step S220. If the processor 300 does not continue to use the DMA channel, the processor 300 controls the DMA channel to operate in the non-safe mode (i.e., the judgment of step S270 is yes). After clearing other registers of the DMA channel (including but not limited to the address register 124 and the count register 126), the processor 300 changes the temporary value of the mode register 122 of the DMA channel to make the DMA channel operate in the non-safe mode (step S280). As a result, other processors 300 operating in the non-secure mode can find the DMA channel in step S220.
[0034] Figure 2 Although the process is taken as an example of the processor 300 operating in the secure mode, a person having ordinary knowledge in the technical field can apply the present invention to the processor 300 operating in the non-secure mode according to the above description, so it is not repeated here.
[0035] The DMA controller or DMA channel of the present invention is applied to an electronic device 10 (e.g., a computer, a portable electronic device, or a system-on-chip device having computing and data storage capabilities), and the processor 300 may be a central processing unit, a microprocessor, a microprocessing unit, a digital signal processor, or a special application integrated circuit of the electronic device 10. In some embodiments, the DMA controller or DMA channel of the present invention has a security mechanism to protect confidential or sensitive data in the electronic device 10. Figure 5 The process of the security mechanism is displayed. The DMA channel or DMA controller operating in the secure mode continuously determines whether the number of control commands received in the non-secure mode is greater than the threshold value (steps S510, S520). The control command of the non-secure mode refers to the control command whose security attribute corresponds to the non-secure mode, which is usually issued by the processor operating in the non-secure mode. When the number of control commands in the non-secure mode received by the DMA channel operating in the secure mode is greater than the threshold value (that is, the judgment of step S520 is yes, which means that there may be a malicious person attempting to steal the data in the secure memory 400), the DMA channel operating in the secure mode issues an interrupt INTR (step S530). Next, the processor 300 operating in the secure mode receives the interrupt INTR, and restarts or shuts down the electronic device 10 in response to the interrupt INTR (step S540) to reduce the risk of data theft.
[0036] In some embodiments, the threshold value may be zero. In other words, as long as a DMA channel or a DMA controller operating in a secure mode receives a control command in a non-secure mode, steps S530 and S540 will be executed.
[0037] In some embodiments, a processor operating in a non-secure mode cannot receive or know the interrupt INTR, so as to improve the reliability of the security mechanism.
[0038] In summary, the present invention proposes a DMA controller and / or DMA channel that can be operated in a secure mode or a non-secure mode, and a method for operating a DMA controller and / or a DMA channel. A DMA controller operating in a non-secure mode and a DMA channel operating in a non-secure mode cannot obtain data moved by a DMA controller operating in a secure mode and data moved by a DMA channel operating in a secure mode.
[0039] Since those with ordinary knowledge in the technical field can understand the implementation details and variations of the method invention of this case through the disclosure of the device invention of this case, in order to avoid redundancy, repeated descriptions are omitted here without affecting the disclosure requirements and feasibility of the method invention. Please note that the shapes, sizes, proportions, and order of steps of the components in the above-mentioned figures are only for illustration and are provided for those with ordinary knowledge in the technical field to understand the present invention, and are not used to limit the present invention.
[0040] Although the embodiments of the present invention are described above, these embodiments are not intended to limit the present invention. Those with ordinary knowledge in the technical field may make changes to the technical features of the present invention based on the explicit or implicit contents of the present invention. All these changes may fall within the scope of patent protection sought by the present invention. In other words, the scope of patent protection of the present invention shall be subject to the scope of the patent application defined in this specification.
[0041]
Explanation of symbols
[0042] 10: Electronic devices
[0043] 100:DMA controller
[0044] 110: Control circuit
[0045] 120-0,120-1:DMA channel
[0046] 121-0,121-1: register file
[0047] 122-0,122-1: Mode register
[0048] 124-0,124-1: Address register
[0049] 126-0,126-1: Count register
[0050] 130: Setting interface
[0051] 140: Main interface
[0052] 200: Bus
[0053] 300: Processor
[0054] 400: Secure Memory
[0055] 500: Non-secure memory
[0056] CM: Control Command
[0057] CRW: read and write command
[0058] QM: Query command
[0059] RC: Response content
[0060] INTR: Interrupt
[0061] 600: Select circuit
[0062] S210~S280, S510~S540: Steps
Claims
1. A direct memory access controller for accessing a memory, wherein the memory includes a secure area and a non-secure area, the direct memory access controller comprising: a direct memory access channel; a mode register for storing a temporary value, wherein when the temporary value is a first value, the direct memory access channel operates in a secure mode, and when the temporary value is a second value, the direct memory access channel operates in a non-secure mode; a setting interface for receiving a control command; and a control circuit coupled to the direct memory access channel and used for setting the temporary value of the mode register according to the control command; in, When the direct memory access channel operates in the secure mode, the direct memory access channel can access the secure area and the non-secure area, and when the direct memory access channel operates in the non-secure mode, the direct memory access channel can access the non-secure area but cannot access the secure area.
2. The direct memory access controller of claim 1, wherein the configuration interface is an advanced peripheral bus. 3 . The direct memory access controller of claim 2 , wherein the control command comprises a security attribute, and the security attribute corresponds to a bit of a protection signal of the advanced peripheral bus.
4. The direct memory access controller according to claim 1, wherein the direct memory access controller receives a query command generated by a processor, and the direct memory access channel generates a reply content in response to the query command, and the reply content includes a current state of the direct memory access channel. 5 . The direct memory access controller of claim 4 , wherein when the processor operates in the secure mode, the reply content further includes a current operation mode of the direct memory access channel.
6. The direct memory access controller of claim 1 , wherein the direct memory access controller receives a query command generated by a processor, the direct memory access channel generates a reply content in response to the query command, and when the direct memory access channel operates in the secure mode and is in an idle state, and the processor operates in the non-secure mode, the reply content indicates that the direct memory access channel is in a busy state.
7. The direct memory access controller according to claim 1, wherein when the direct memory access channel operates in the secure mode and the received control command is a non-secure mode control command, the direct memory access channel generates an interrupt in response to the non-secure mode control command.
8. An electronic device comprising: A processor, configured to generate a control command, wherein the control command is used to set an operation mode of a direct memory access controller; A memory including a secure area and a non-secure area; and The direct memory access controller is coupled to the processor and the memory via a bus, and comprises: a direct memory access channel; a configuration interface, wherein the direct memory access controller receives the control command through the configuration interface; and a mode register for storing a temporary value corresponding to the control command, wherein when the temporary value is a first value, the direct memory access channel operates in a secure mode, and when the temporary value is a second value, the direct memory access channel operates in a non-secure mode; in, When the direct memory access channel operates in the secure mode, the direct memory access channel can access the secure area and the non-secure area, and when the direct memory access channel operates in the non-secure mode, the direct memory access channel can access the non-secure area but cannot access the secure area.
9. A method of operating a direct memory access controller, the direct memory access controller being used to access a memory, the memory comprising a secure area and a non-secure area, the method comprising: Finding a direct memory access channel in the direct memory access controller that is in an idle state, the direct memory access channel further comprising a mode register for storing a temporary value, wherein when the temporary value is a first value, the direct memory access channel operates in a secure mode, and when the temporary value is a second value, the direct memory access channel operates in a non-secure mode; Setting a temporary value of a mode register of the direct memory access channel to enable the direct memory access channel to operate in a safe mode; Setting an address register and a count register of the direct memory access channel; and The direct memory access channel is controlled to perform data movement based on the address register and the count register.
10. The method according to claim 9, wherein the step of setting the temporary value of the mode register of the direct memory access channel comprises: Sending a control command via an advanced peripheral bus to set the mode register; in, The control command includes a security attribute corresponding to a bit of a protection signal of the advanced peripheral bus.
Citation Information
Patent Citations
Method for wiping cache of processor and processor
CN103186474A
Security protection method for off-chip nonvolatile memory
CN110609799A
Direct memory access control method
JP1983096329A
Method and apparatus for local and distributed data memory access ("dma") control
TW200506626A
Microcomputer structure and method having direct memory access function
TW200523797A
