Previously we learned that the CPU reads data from the disk sector through the read/write Io address. We also learned that the CPU and the disk may be connected through the frontend bus, the Northbridge chip, and the PCI connection between the North and South bridges, and the disk controller on the Southern bridge, and finally can reach the disk drive control head to read and write disk data. Now we can connect these scenarios to see more specific interaction processes.
First, open the Device Manager in windows and find the disk controller and disk drive. The names of these two devices are confusing. Looking at the properties of these two devices, we can see that the disk controller properties are clearly written with the PCI address, such as the position: PCI bus 0, device 31, function 2. That is to say, our disk controller is actually a PCI device connected to the PCI bus, and the PCI bus is eventually connected to the North Bridge, that is, the host Main Bridge.
Since a PCI device has a PCI address space, the address space is mapped to the storage space by the host Main Bridge. The CPU actually accesses the PCI address space through the host Main Bridge. The working principle of the PCI bus will be studied in detail later. Now we know that the so-called disk controller may be a PCI device.
However, the disk controller is not just a PCI device. Its main function is to control the disk drive and issue commands to the disk drive for disk read/write. Why is it designed like this? It is clearly for decoupling, so that the hard disk and other computer components can develop independently. For example, before PCI, we used a low-speed ISA bus to connect to the IDE hard disk. Now, the ISA bus is replaced by the PCI bus, and we also need to use the IDE hard disk, in addition, we hope that the existing IDE hard drive can be used in the new computer system without any modification.
This is not complicated. After the new bus comes out, a "bus adapter" or an interface must be provided to connect the previous IO Device to the new bus, on the one hand, this interface can interact with the bus, and on the other hand, you need to know how to control the IO Device. In this way, the CPU commands can be converted to the commands on the IO Device. Our disk controller is such an interface. It knows the instruction set of the disk device, so after obtaining the CPU command, it can be translated into the control command of the disk device. In fact, many traditional I/O devices are integrated with a controller on the Southern bridge to help I/O devices interact with local bus data. This is also the value of nanqiao.
Therefore, we know why the same disk can be connected to both the computer of the ISA bus and the computer of the PCI bus. The external interface of the disk is neither an interface of the ISA Device, it's not a PCI device interface, because they use different disk drives. This allows the disk device to develop its interface technology independently without being bound to a single bus. This is more conducive to the orderly development of the industry. Finally, let's review the disk read/write technology. If we want to access a disk, we must find the disk drive and edit its I/O space (this may be confusing. It will be clear when we talk about Io unified memory addressing later ), then, according to the usage instructions of the disk controller, the disk read/write command is sent to it, and finally the result is obtained.
Fortunately, the previous IDE disk controller has a fixed I/O space, that is, what we talked about in "CPU Interpretation 3: how the program controls read/write hard disks ".0x1f0-0x1f7 ide. In this article, we will explain in detail how to write read/write disk commands to these I/O registers of the disk controller to obtain disk data.
However, it would be too unfriendly for programmers to write data into these registers every time they read and write data to the disk. As a result, the programmer encapsulates these operations and provides them as drivers, even more advanced APIs are provided for programmers to call. This is part of the scope of software technology, but no matter how software programs are written, every disk read/write operation, it must be the CPU command to control the disk controller, and then the disk controller to control the disk, which is the last path.