Direct memory access controller, electronic device using the same, and method for operating the same
By designing a direct memory access controller and using a mode register to switch the operating mode of the DMA controller or channel, the problems of waste of resources and difficulty in mode switching in the prior art are solved, and flexible mode switching of the DMA controller and Savings of hardware resources.
Patent Information
- Application Number
- CN202011112673.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-16
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2040-10-16
AI Technical Summary
Existing systems waste resources when sharing DMA controllers and it is difficult to switch between privileged and normal modes, resulting in increased hardware resource consumption and cost.
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 the operating mode of the DMA controller or channel to realize the privileged mode. Switching between normal mode reduces hardware resource consumption.
It realizes flexible switching between privileged mode and normal mode by DMA controller or its channel, saving hardware resources and reducing costs.
Smart Images

Figure CN114385529B_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] Electronic devices usually store high-priority data in a privileged area of memory (also called privileged memory), and store normal (i.e., low-priority) data in a normal area of memory (also called normal memory). Therefore, a system on a chip (SoC) that can operate in privileged mode and normal mode usually uses independent DMA controllers or independent DMA channels for the two modes. However, since a DMA controller or DMA channel is not always used by the same privilege level (i.e., privileged mode or normal 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 privileged area and a common 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 privileged mode, and when the temporary value is a second value, the direct memory access channel operates in a common 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 privileged mode, the direct memory access channel can access the privileged area and the common area, and when the direct memory access channel operates in the common mode, the direct memory access channel can access the common area but cannot access the privileged 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 privileged area and a normal area. The direct memory access controller is coupled to 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 privileged mode, and when the temporary value is a second value, the direct memory access channel operates in a normal mode. When the direct memory access channel operates in the privileged mode, the direct memory access channel can access the privileged area and the common area, and when the direct memory access channel operates in the common mode, the direct memory access channel can access the common area but cannot access the privileged 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 privileged area and a common 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 privileged 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 privileged mode and normal mode. Compared with the conventional technology, the DMA controller or its DMA channel of the present invention can realize the DMA operation of privileged mode and the DMA operation of normal 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 privilege 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 privileged mode or a normal 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 the privileged mode or the normal mode at the same time, or one can operate in the privileged mode and the other in the normal 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 the privileged 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 the normal mode.
[0021] When the DMA controller 100 or the DMA channel 120 is set to the privileged mode, the DMA controller 100 or the DMA channel 120 operates in the privileged mode, and all subsequent setting or reading operations need to be performed using the control commands of the privileged mode. If the control commands of the normal mode attempt to read the DMA controller 100 or the DMA channel 120, or attempt to set the DMA controller 100 or the DMA channel 120 to move data, the DMA controller 100 operating in the privileged mode or the DMA channel 120 operating in the privileged mode will reject these operations. In some embodiments, when the software or hardware of the normal mode attempts to read the settings of the DMA controller 100 operating in the privileged mode or the settings of the DMA channel 120 operating in the privileged mode, the DMA controller 100 operating in the privileged mode or the DMA channel 120 operating in the privileged mode does not return the real value, but returns "0", a reserved value or a random value, so as to prevent the software or hardware of the normal mode from knowing the settings of the DMA controller 100 operating in the privileged mode or the settings of the DMA channel 120 operating in the privileged mode.
[0022] The setting interface 130 and the host 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 privileged memory 400, and the normal memory 500 through the bus 200. The bus 200 may also be an interconnect or a bus matrix. The privileged memory 400 and the normal memory 500 may be two independent physical memories (e.g., a dynamic random access memory (DRAM)), or different blocks or regions (i.e., privileged / normal blocks, or privileged / normal regions) of the same physical memory. 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 may be used to set the temporary value of the mode register 122 of the DMA channel 120. The control command CM includes a privilege attribute, and the processor 300 generates a control command CM of a privileged mode or a control command CM of a normal mode by controlling the value of the privilege attribute. More specifically, the privileged attribute of the control command CM generated by the processor 300 operating in the privileged mode is a first logic value (eg, logic 1), and the privileged attribute of the control command CM generated by the processor 300 operating in the normal 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 privileged attribute. For example, when the privileged 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 privileged 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 privileged attribute is one bit of a protection signal (Pprot) (e.g., the bit value is 0, i.e., Pprot[0]). 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 privileged 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 normal mode. The processor 300 operating in the privileged 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 privileged mode, another processor in the normal mode cannot obtain the DMA controller 100 or the DMA channel 120 to transfer data for itself.
[0025] When the DMA channel 120 operates in the privileged mode, the DMA channel 120 can access the privileged memory 400 and the normal memory 500, and when the DMA channel 120 operates in the normal mode, the DMA channel 120 can access the normal memory 500 but cannot access the privileged memory 400. More specifically, the DMA channel 120 transmits a read / write command CRW to the privileged memory 400 and / or the normal memory 500 through the host interface 140 and the bus 200. The host interface 140 can distinguish between commands in the privileged mode and commands in the normal mode. The read / write command CRW includes a privilege attribute, and the privileged memory 400 determines whether to allow the read and / or write operation based on the privilege attribute. For example, when the DMA channel 120 operates in the privileged mode, the privilege attribute of the read / write command CRW issued by the DMA channel 120 is a first logic value (corresponding to the privileged mode), so that the privileged memory 400 and the ordinary memory 500 are allowed to read and / or write operations; when the DMA channel 120 operates in the ordinary mode, the privilege attribute of the read / write command CRW issued by the DMA channel 120 is a second logic value (corresponding to the ordinary mode), so that the privileged memory 400 is not allowed to read and / or write operations, but the ordinary 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 eXtensible Interface (AXI). In some embodiments, the bus 200 determines whether the DMA controller 100 or the DMA channel 120 is allowed to access the privileged 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 privileged 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, for example, 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., privileged mode or normal 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 privileged 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 normal mode. Figure 3A and Figure 3B In the example, assume that the current operation modes of DMA channel 0 to DMA channel 3 are normal mode, normal mode, privileged mode and privileged 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 privileged 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 privileged 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 normal mode, the reply content RC of the DMA channel 120 includes the state but not the operation mode, and the state in the reply content RC is not necessarily the real state of the DMA channel 120 at the moment. More specifically, when the DMA channel operating in normal mode receives a polling signal from the processor 300 operating in normal mode, the DMA channel operating in normal mode replies to the current state but does not reply to the operation mode; when the DMA channel operating in privileged mode receives a polling signal from the processor 300 operating in normal mode, the DMA channel operating in privileged 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 normal mode from accessing the DMA channel operating in privileged mode, the DMA channel 2 replies to a fake state or a dummy state. Therefore, the processor 300 operating in normal mode can know the real state of the DMA channel operating in normal mode, but cannot know the real state of the DMA channel operating in privileged mode, and the processor 300 operating in normal mode cannot know the operation mode of the DMA channel. Under such a design, the processor 300 operating in the normal mode cannot configure the DMA controller 100 operating in the privileged mode or the DMA channel 120 operating in the privileged mode.
[0030] In some embodiments, the processor 300 operating in the normal 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 make the DMA controller 100 or the DMA channel 120 leave the privileged mode.
[0031] In some embodiments (such as Figure 4 ), the DMA channel 120 operating in the privileged mode uses the selection circuit 600 (e.g., a multiplexer) to restore the real state or the virtual state based on the privileged attribute of the control command CM. When the privileged attribute is logic 1 (corresponding to the privileged mode), the DMA channel 120 restores the real state; when the privileged attribute is logic 0 (corresponding to the normal 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 the privileged 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 normal 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 normal 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 normal 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 normal mode (step S280). In this way, other processors 300 operating in the normal 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 privileged mode, a person skilled in the art can apply the present invention to the processor 300 operating in the normal mode according to the above description, so it will not be described in detail.
[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 privilege mechanism to protect confidential or sensitive data in the electronic device 10. Figure 5 The process of the privilege mechanism is displayed. The DMA channel or DMA controller operating in the privileged mode continuously determines whether the number of control commands of the normal mode received is greater than the threshold value (steps S510, S520). The control command of the normal mode refers to the privileged attribute of the control command corresponding to the normal mode, which is usually issued by the processor operating in the normal mode. When the number of control commands of the normal mode received by the DMA channel operating in the privileged 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 privileged memory 400), the DMA channel operating in the privileged mode issues an interrupt INTR (step S530). Then, the processor 300 operating in the privileged 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 the DMA channel or DMA controller operating in the privileged mode receives a control command of the normal mode, steps S530 and S540 will be executed.
[0037] In some embodiments, a processor operating in a normal mode cannot receive or know the interrupt INTR, so as to improve the reliability of the privilege mechanism.
[0038] In summary, the present invention proposes a DMA controller and / or DMA channel that can operate in privileged mode or normal mode, and a method for operating a DMA controller and / or DMA channel. A DMA controller operating in normal mode and a DMA channel operating in normal mode cannot obtain data moved by a DMA controller operating in privileged mode and data moved by a DMA channel operating in privileged 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:Privileged memory
[0055] 500: Normal 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 privileged area and a common 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 privileged mode, and when the temporary value is a second value, the direct memory access channel operates in a normal 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 privileged mode, the direct memory access channel can access the privileged area and the common area, and when the direct memory access channel operates in the common mode, the direct memory access channel can access the common area but cannot access the privileged area.
2. The direct memory access controller according to claim 1, wherein the configuration interface is an advanced peripheral bus.
3. The direct memory access controller according to claim 2, wherein the control command comprises a privilege attribute, and the privilege 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 according to claim 4, wherein when the processor operates in a privileged 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 privileged mode and is in an idle state, and the processor operates in a normal 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 privileged mode and the received control command is a normal mode control command, the direct memory access channel generates an interrupt in response to the normal 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 privileged area and a normal 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 privileged mode, and when the temporary value is a second value, the direct memory access channel operates in a normal mode; in, When the direct memory access channel operates in the privileged mode, the direct memory access channel can access the privileged area and the common area, and when the direct memory access channel operates in the common mode, the direct memory access channel can access the common area but cannot access the privileged area.
9. A method for operating a direct memory access controller, the direct memory access controller being used to access a memory, the memory comprising a privileged area and a normal area, the method comprising: Finding a direct memory access channel in the direct memory access controller that is in an idle state; Setting a temporary value of a mode register of the direct memory access channel to make the direct memory access channel operate in a privileged mode; Setting an address register and a count register of the direct memory access channel; Controlling the direct memory access channel to perform data movement based on the address register and the count register; and After the data migration is completed, it is determined whether to control the direct memory access channel to operate in a normal mode.
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 privilege attribute corresponding to a bit of a protection signal of the advanced peripheral bus.
