This application claims the priority benefit of Taiwan application serial No. 102118960, filed on May 29, 2013. The entirety of the above-mentioned patent application is hereby incorporated by reference herein and made a part of specification.
1. Field of the Invention
The invention relates to a method for data management.
2. Description of the Related Art
Conventionally, an electronic device or a computer system which supports universal serial bus (USB) transmission usually includes a host controller. The host controller maintains one or more groups of device context data according to USB devices coupled thereto, and each group of the device context data corresponds to one USB device.
According to the USB xHCI standard specification, the memory space of each storage block of the device context data 10 is at least 32 bytes. Thus, when one more USB device is coupled thereto, the host controller needs more 1 k bytes memory space to store the device context data 10 correspondingly. However, once the host controller detects a USB device coupled thereto, the device context data 10 shown in
A method for data management is provided. The method can dynamically manage device context data maintained by the host controller, and effectively save memory space for storing the device context data.
A method for data management adapted for a host controller to store device context data of at least one universal serial bus (USB) device is provided, and the host controller includes a memory. The method comprising following steps: storing a device slot index table in the memory; allocating a plurality of memory blocks of the memory according to state information of the USB device when that the USB device is coupled to the host controller is detected, so as to store the device context data of the USB device, and storing an initial address of the memory blocks in the device slot index table; and releasing the memory blocks and erasing the initial address of the memory blocks stored in the device slot index table when the USB device is detected being detached from the host controller.
These and other features, aspects and advantages of the present invention will become better understood with regard to the following description, appended claims, and accompanying drawings.
The host controller 22 includes a memory 23, and the memory 23 may be a volatile memory, such as a dynamic random access memory (DRAM), or a non-volatile memory. The memory 23 can be disposed in the host controller 22 as a module, or connected to the host controller 22 externally, which is not limited herein. Moreover, the host controller 22 may also include or connect other non-volatile memories to store software or firmware.
Please refer to
Then, in the step S320, when the host controller 22 detects that the first USB device 21 is coupled to the host controller 22, the host controller 22 allocates a plurality of memory blocks in the memory 23 according to the state information of the first USB device 21 to store the device context data of the first USB device 21. For example, the host controller 22 can assess the needed memory space or the number of the needed memory blocks according to endpoint states of the first USB device 21. When the needed memory space or the number of the needed memory blocks is large, the host controller 22 allocates more memory blocks to store the device context data of the USB device 21. On the contrary, when the needed memory space or the number of the needed memory blocks is small, the host controller 22 allocates less memory blocks to store the device context data of the first USB device 21.
Then, the host controller 22 stores an initial address of the memory blocks to the device slot index table. The initial address in the embodiment may be an initial physical address of the memory blocks in the memory 23, and the host controller 22 can find the corresponding memory block and read the data stored in the memory block accordingly.
For example,
The host controller 22 stores the initial address of the first device context data index block 42 to the device slot index table 41, and the initial address of the first device context data index block 42 is regarded as a common initial address of the first device context data index block 42, the slot context queue head block 43 and the endpoint context queue head block 44. Then, the host controller 22 associates the first device context data index block 42, the slot context queue head block 43 and the endpoint context queue head block 44. For example, the host controller 22 can associate the first device context data index block 42 and the slot context queue head block 43, and associate the first device context data index block 42 and the endpoint context queue head block 44. Thus, the host controller 22 can inquire the device slot index table 41 to obtain the initial address of the first device context data index block 42, and find the slot context queue head block 43 and the endpoint context queue head block 44 in the memory 23 according to the association of the first device context data index block 42, the slot context queue head block 43 and the endpoint context queue head block 44.
In the embodiment, the first device context data index block 42 is similar with an integrated index block, and it stores the initial address corresponding to each data storage block of the first USB device 21. The host controller 22 can inquire the data in the first device context data index block 42 to find other data storage blocks (such as the slot context queue head block 43 and the endpoint context queue head block 44). The slot context queue head block 43 stores the slot context data (which is similar with the data stored in the storage block 11 in
The device slot index table 41, the first device context data index block 42, the slot context queue head block 43 and the endpoint context queue head block 44 are illustrated as follows.
In the embodiment, each first device context data index block includes a slot context queue head index column and an endpoint context queue head slot column. The slot context queue head index column stores the initial address of the slot context queue head block, and the endpoint context queue head slot column stores the initial address of the endpoint context queue head block.
For example,
In another example,
In the step S310, the memory blocks allocated by the host controller 22 further includes a plurality of sub-endpoint context data blocks, and the sub-endpoint context data blocks store the endpoint context data of the plurality of sub-endpoints of at least one USB device, such as the first USB device. Taking the embodiment in
Additionally, the host controller 22 can adjust the number of the allocated sub-endpoint context data blocks according to the state information of the first USB device 21, which reduces the number of the sub-endpoint context data blocks to save the memory space. For example, the host controller 22 can assess the number of the needed sub-endpoint context data blocks according to the state information of the first USB device 21. Then, the host controller 22 allocates the sub-endpoint context data blocks in the memory 23 according to the assessing result.
In the embodiment, the host controller 22 can dynamically allocate one or more sub-endpoint context data blocks according to whether the endpoint context data of the endpoint context 1 IN/OUT to the endpoint context IN/OUT 15 exist or need to be stored, which makes the number of the sub-endpoint context data blocks correspond to the endpoint context data of the endpoint context 1 IN/OUT to the endpoint context 15 IN/OUT which need to be stored, and it does not need to constantly maintain the storage blocks 13_1 to 13_30 as the device context data 10 in
Furthermore, the first device context data index block may further include a plurality of first sub-endpoint context data index columns in order to find the sub-endpoint context data blocks. The first sub-endpoint context data index columns are used for storing the initial address of a first part of the sub-endpoint context data blocks (such as the sub-endpoint context data blocks storing the endpoint context data of the endpoint context 1 IN/OUT to the endpoint context 10 IN/OUT).
For example,
The first device context data index block 42 may further include the columns 422_3 to 422_20. The column 422_3 stores the initial address of the sub-endpoint context data block which stores the endpoint context data of the endpoint context 1 IN. The column 422_4 stores the initial address of the sub-endpoint context data block which stores the endpoint context data of the endpoint context 1 OUT. The column 422_5 stores the initial address of the sub-endpoint context data block which stores the endpoint context data of the endpoint context 2 IN. The columns 422_6 to 422_20 can be deduced by analogy. Moreover, due to the limitation of the number of the columns of the first device context data index block 42, the first device context data index block 42 only can store the initial address of the sub-endpoint context data blocks (which is the initial address of the first part of the sub-endpoint context data blocks) of the endpoint context data of the endpoint context 1 IN/OUT to the endpoint context 10 IN/OUT.
In the step S310, in order to store the initial address of the sub-endpoint context data blocks of the endpoint context data of the endpoint context 11 IN/OUT to the endpoint context 15 IN/OUT, the host controller 22 can allocate a second device context data index block 82 to store a plurality of second sub-endpoint context data index columns. The second sub-endpoint context data index column stores the initial address of a second part of the sub-endpoint context data blocks (such as the sub-endpoint context data blocks which store the endpoint context data of the endpoint context 11 IN/OUT to the endpoint context 15 IN/OUT). The host controller 22 can store the initial address of the second device context data index block 82 to the column 422_21 of the first device context data index block 42, and the column 422_21 is an associated column.
The second device context data index block 82 includes the columns 822_1 to 822_10. The column 822_1 stores the initial address of the sub-endpoint context data blocks which store the endpoint context data of the endpoint context 11 IN. The column 822_2 stores the initial address of the sub-endpoint context data blocks which store the endpoint context data of the endpoint context 11 OUT. The column 822_3 stores the initial address of the sub-endpoint context data blocks which store the endpoint context data of the endpoint context 12 IN, and the other columns 822_4 to 822_10 can be deduced by analogy.
Consequently, when the endpoint context data of a part or all of the endpoint context 1 IN/OUT to the endpoint context 10 IN/OUT need to be stored, the host controller 22 allocates the first device context data index block 42 to store the initial address of each sub-endpoint context data block. When the endpoint context data of the USB device which need to be stored include the endpoint context data of the endpoint context 11 IN/OUT to the endpoint context 15 IN/OUT, the host controller 22 allocates the second device context data index block 82 additionally to store the initial address of each sub-endpoint context data block to the first device context data index block 42 and the second device context data index block 82 in the way stated above.
For example, it is assumed that the endpoint 1 IN/OUT and the endpoint 15 IN/OUT of the USB device 21 have a specific function state, and the host controller 22 needs to store the endpoint context data of the endpoint context 1 IN, the endpoint context 1 OUT, the endpoint context 15 IN and the endpoint context 15 OUT of the first USB device 21. The host controller 22 allocates the sub-endpoint context data blocks 85_1 to 85_4 (which means m=4). The sub-endpoint context data blocks 85_1 stores the endpoint context data of the endpoint context 1 IN of the USB device 21. The sub-endpoint context data block 85_2 stores the endpoint context data of the endpoint context 1 OUT of the first USB device 21. The sub-endpoint context data block 85_3 stores the endpoint context data of the endpoint context 15 IN of the first USB device 21. The sub-endpoint context data block 85_4 stores the endpoint context data of the endpoint context 15 OUT of the first USB device 21.
Then, the host controller 22 stores the initial address of the sub-endpoint context data blocks 85_1 to the column 422_3 of the first device context data index block 42, stores the initial address of the sub-endpoint context data blocks 85_2 to the column 422_4 of the first device context data index block 42, stores the initial address of the sub-endpoint context data blocks 85_3 to the column 822_9 of the second device context data index block 82, and stores the initial address of the sub-endpoint context data blocks 85_4 to the column 822_10 of the second device context data index block 82, and thus the host controller 22 can find the sub-endpoint context data blocks 85_1 to 85_4 via the column 422_3, the column 422_4, the column 822_9 and the column 822_10 conveniently.
In the embodiment, only the memory blocks which are needed to store the necessary data are allocated. However, in the device context data 10 in
Please refer to
On the other hand, when the USB devices are coupled to the host controller, the host controller can also set a pointer in an endpoint context table corresponding to each USB device, and the host controller rapidly obtains and inquires the endpoint context table corresponding to other USB devices according to the pointer.
For example,
The difference between the data management system 90 and the data management system 20 in
In order to access the information of the different USB devices and dynamically manage the memory blocks, the host controller 22 can set a forward pointer and a backward pointer, respectively, in the endpoint context table corresponding to the first USB device 21, the second USB device 94 and the third USB device 95. The host controller 22 can find the endpoint context queue head block corresponding to the first USB device 21, the second USB device 94 and the third USB device 95 in the memory 23 according to the forward pointer and the backward pointer in each endpoint context table, and it can inquire the information stored in the endpoint context table of each endpoint context queue head block.
For example,
It is assumed that the second USB device 94, the first USB device 21 and the third USB device 95 are coupled to the host controller 22 in sequence. The column 742_1 stores the initial address (which is a forward pointer) of the endpoint context queue head block corresponding to the second USB device 94, and the column 742_2 stores the initial address (which is a backward pointer) of the endpoint context queue head block corresponding to the third USB device 95. Thus, the host controller 22 can find the endpoint context queue head block corresponding to the USB second device 94 according to the forward pointer in the column 742_1 and inquire the endpoint context table 101. The host controller 22 can also find the endpoint context queue head block corresponding to the third USB device 95 according to the backward pointer in the column 742_2 and inquire the endpoint context table 102.
Similarly, the endpoint context table 101 and the endpoint context table 102 can include the forward pointer column and the backward pointer column, respectively. For example, the forward pointer column of the endpoint context table 101 records “Null”, which means the forward pointer in the endpoint context table 101 does not point to other endpoint context tables. The backward pointer column of the endpoint context table 101 records the initial address of the endpoint context queue head block corresponding to the USB device 21. Moreover, the forward pointer column of the endpoint context table 102 can also record the initial address of the endpoint context queue head block corresponding to the USB device 21, and the backward pointer column of the endpoint context table 102 records “Null”, which means the backward pointer in the endpoint context table 102 does not point to other endpoint context tables.
In sum, in the method for data management according to the embodiments, when it is detected that a USB device is coupled to the host controller, the needed the memory space and the number of the needed memory blocks are assessed according to the state information of the USB device. Then, a plurality of the memory blocks in the memory are allocated according to an assess result to store the device context data of the USB device. When it is detected that the USB device is detached from the host controller, the memory blocks are released instantly. Thus, the device context data maintained by the host controller can be dynamically managed, and the memory space for storing the device context data is effectively saved. Furthermore, the endpoint context table corresponding to each USB device can be rapidly inquired by setting a pointer in the endpoint context table, which can reduce reading delay.
Although the present invention has been described in considerable detail with reference to certain preferred embodiments thereof, the disclosure is not for limiting the scope. Persons having ordinary skill in the art may make various modifications and changes without departing from the scope. Therefore, the scope of the appended claims should not be limited to the description of the preferred embodiments described above.
Number | Date | Country | Kind |
---|---|---|---|
102118960 | May 2013 | TW | national |