PCI serial port equipment general driving system based on Loongson platform and configuration method
By designing a universal driver system for PCI serial port equipment based on the Loongson platform, combined with the hardware resource characteristics of Loongson processor and supporting bridges, the problem of lack of a universal serial port driver framework under the Kirin operating system is solved, code reuse and cost reduction are achieved, and the needs of different usage scenarios are met.
Patent Information
- Application Number
- CN202510040554.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-10
- Publication Date
- 2025-06-03
AI Technical Summary
The lack of a universal serial driver framework under the Kirin operating system has led to high cost of repeated development and cannot meet the needs of different scenarios of military control equipment.
Design a universal driver system for PCI serial port equipment based on the Loongson platform, combining the hardware resources characteristics of Loongson processor and supporting bridge chips to realize code reuse. Through the configuration method of the universal driver system for PCI serial port equipment, it includes configuring the PC device space, initializing the PCI device in the kernel, loading the driver, realizing the driver of the PCI device as a character device, and binding interrupts to the specified CPU.
It realizes code reuse, reduces development costs, meets the needs of different usage scenarios, and improves system resource utilization.
Smart Images

Figure CN120086163A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer operating systems, especially a general driver system and configuration method for PCI serial port devices based on the Loongson platform. Background Art
[0002] Kylin operating system, as the mainstream military desktop operating system, is more and more widely used. To be compatible with certain devices, there is a great demand for serial port devices in military control devices. Currently, under the Kylin operating system, there is a lack of a general driver framework, resulting in a relatively high cost of repeated development. Therefore, a general serial port driver framework under the Kylin operating system is designed to meet the usage in different scenarios of military control devices. Summary of the Invention
[0003] The purpose of the present invention is to overcome the deficiencies of the prior art, and propose a general driver system and configuration method for PCI serial port devices based on the Loongson platform, which fully combines the hardware resource characteristics of the Loongson processor and the supporting bridge chip to meet different usage scenarios, realize code reuse, and reduce the development cost.
[0004] The present invention solves its technical problems by adopting the following technical solutions:
[0005] A general driver system for PCI serial port devices based on the Loongson platform includes a Loongson processor 3A3000, a Loongson bridge chip 7A1000, and a PCIe-to-PCI bridge chip. Among them, the Loongson processor 3A3000 and the Loongson bridge chip 7A1000 are connected to each other. The PCIe interface of the Loongson bridge chip 7A1000 is connected to the input end of the PCIe-to-PCI bridge chip. The output end of the PCIe-to-PCI bridge chip is respectively connected to PCI devices. All PCI devices are connected under this transfer bridge chip and share the same interrupt.
[0006] A configuration method for a general driver system for PCI serial port devices based on the Loongson platform is characterized by including the following steps:
[0007] Step 1, configure the PC device space;
[0008] Step 2, initialize the PCI device in the kernel and generate a pci_dev structure diagram;
[0009] Step 3, according to the generated pci_dev structure diagram, load the driver and call the pci_dev members;
[0010] Step 4, detect the corresponding pci_dev through probe(), and provide the corresponding information to the PCI device driver;
[0011] Step 5, implement the driver for the PCI device as a character device;
[0012] Step 6: Bind the interrupt to the specified CPU.
[0013] Moreover, the specific implementation method of step 3 is as follows: Use pci_driver to define the PCI driver. The pci_driver includes functions such as detection / removal, suspend / resume of PCI devices; and it involves four important structure members: device name, device list, device probing function, and device removal function.
[0014] Moreover, the specific implementation method of step 4 is as follows: The member function probe() probes the PCI device according to the device list defined by the struct pci_dev_id structure and saves the configuration information to the parameter pci_dev; in the probe() function, the initialization of the PCI device and the registration of the device's own identity driver need to be completed.
[0015] Moreover, the specific implementation method of step 6 is as follows:
[0016] Step 6.1: Interrupt service program design: The interrupt handling of the PCI serial device driver is mainly responsible for identifying interrupts, responding to interrupts, and waking up sleeping processes, including: identifying interrupt resources; responding to interrupt requests; waking up the sleeping process corresponding to the interrupt;
[0017] Step 6.2: Design of the API interface with the user layer: The PCI serial device adopts the character device model. In Linux, a character device is represented by the structure cdev, and its structure definition is as follows:
[0018]
[0019] Among them, the member functions in the file_operations structure are the main content of the character device driver program design;
[0020] Several commonly used member functions of the file_operations structure are: read() is used to read data from the device and calls copy_to_user to copy count kernel data to the user space buf. The read() system call in the application program will call this function; the function write() sends data to the device, calls copy_from_user() to copy count data from the user space buf to the kernel and then sends it to the device. The write() system call in the application program will call this function; ioctl() provides the implementation of device-related control commands; open() is the device opening function; release() is the device release function; these functions are defined in the driver and the file_operations structure is initialized.
[0021] The advantages and positive effects of the present invention are:
[0022] The present invention includes Loongson processor 3A3000, Loongson bridge chip 7A1000, and a PCIe-to-PCI bridge chip. Among them, Loongson processor 3A3000 and Loongson bridge chip 7A1000 are connected to each other. The PCIe interface of Loongson bridge chip 7A1000 is connected to the input end of the PCIe-to-PCI bridge chip, and the output ends of the PCIe-to-PCI bridge chip are respectively connected to PCI devices. By fully combining the hardware resource characteristics of Loongson processor and the supporting bridge chips, the present invention can meet different usage scenarios, realize code reuse, and reduce the development cost. Brief Description of the Drawings
[0023] Figure 1 is the system block diagram of the present invention;
[0024] Figure 2 is the method flow chart of the present invention. Detailed Embodiment
[0025] The following further describes the present invention with reference to the drawings.
[0026] A general driver system for PCI serial port devices based on the Loongson platform, as Figure 1 shown, includes Loongson processor 3A3000, Loongson bridge chip 7A1000, and a PCIe-to-PCI bridge chip. Among them, Loongson processor 3A3000 and Loongson bridge chip 7A1000 are connected to each other. The PCIe interface of Loongson bridge chip 7A1000 is connected to the input end of the PCIe-to-PCI bridge chip, and the output ends of the PCIe-to-PCI bridge chip are respectively connected to PCI devices.
[0027] Based on the basic principle of Linux device drivers and combined with the characteristics of PCI bus devices, the present invention constructs a PCI serial port device driver framework, and elaborates the development process of Linux device drivers through the development of the drivers for the actually used PCI serial port devices, and uses programming to verify that the drivers can correctly send and receive data.
[0028] The object of the driver is the peripheral device rather than the CPU. Linux has three basic categories of device types: character devices, block devices, and network devices. Except for network devices, character devices and block devices are both mapped to files and directories in the file system. Therefore, from the perspective of application programs, the operation on the device file is the operation on the corresponding hardware device. The calls to system call interfaces such as open(), write(), read() and other functions will indirectly call the member functions such as open(), write(), read() in the driver structure. And the file_operations member function of character devices is directly provided by the device driver.
[0029] A configuration method for a general driver system of a PCI serial port device based on the LoongArch platform. Essentially, PCI is just a bus, and PCI devices can be character devices, network devices, or block devices. In the present invention, according to the device characteristics and usage scenarios, the character device driver module is selected. For a PCI serial port device, it has the dual identities of a PCI device and a serial port device. Therefore, its driver framework includes two parts: the PCI device driver and the device itself driver. In addition to implementing the PCI driver part, the main body of the driver still acts as a character device driver. It is characterized by the following steps: As Figure 2 shown, it includes the following steps:
[0030] Step 1: Configure the PC device space.
[0031] Step 2: The kernel initializes the PCI device and generates a pci_dev structure diagram.
[0032] Step 3: According to the generated pci_dev structure diagram, load the driver and call the pci_dev members.
[0033] When the PCI device is just powered on, only the configuration space of the device can be accessed. This space stores all the information required for the operation of the PCI device, such as the vendor ID, device ID, resource requirements, interrupt information, etc. By reading and programming this space information, the configuration of the PCI device can be completed.
[0034] During the startup process of the Linux kernel, the kernel calls pci_init() to complete the initialization of the PCI device. After the kernel initializes the PCI device, kernel data structures for managing the PCI subsystem are generated in the kernel. There are mainly two of these data structures: the pci_bus structure and the pci_dev structure. Among them, the structure pci_bus represents the PCI bus, and the structure pci_dev represents the PCI device.
[0035] Use pci_driver to define the PCI driver. The structure diagram is as follows. This structure contains functions such as detection / removal, suspend / resume of the PCI device; this structure diagram involves four important structure members: device name, device list, device probing function, and device removal function. These four members are mainly implemented in the driver framework.
[0036]
[0037] Step 4: Detect the corresponding pci_dev through probe(), and provide the corresponding information to the PCI device driver.
[0038] a) Implementation of the PCI serial port device data structure:
[0039] In the PCI device driver, three important static global variables, device_table[], UartCard_driver, and UartCard_fops, need to be defined. Among them, device_table[] represents the PCI devices supported by the current driver, UartCard_driver represents the current PCI driver program, and UartCard_fops represents the set of device file operation entry point functions provided by the driver to the application program;
[0040] b) Driver loading and unloading functions:
[0041] After defining the three data structures in 1), the driver loading interface and unloading interface for the PCI serial device need to be designed next;
[0042] c) Detection and removal interfaces for serial devices:
[0043] After successfully scanning for PCI devices, the PCI subsystem needs to call the detection interface function implemented by the device driver to find the driver that matches the PCI device. The detection function interface first allocates storage space for the device instance. If the application is successful, the PCI device is enabled. The detection interface in the present invention is designed as follows:
[0044] 1) Allocate storage space for the device instance. If the allocation is successful, proceed to 2); otherwise, return.
[0045] 2) Enable the PCI device. If the enabling is successful, proceed to step 3); otherwise, return.
[0046] 3) Initialize the private variables related to the device instance;
[0047] 4) Obtain I / O and MEM resources;
[0048] 5) Apply for I / I and MEM space. If the application is successful, the initialization is successful; otherwise, return.
[0049] The removal interface used in conjunction with the detection interface is designed as follows:
[0050] 1) Release the virtual address space;
[0051] 2) Release the I / O and MEM resources;
[0052] Disable the PCI device.
[0053] Step 5: Implement the driver for the PCI device as a character device.
[0054] Essentially, PCI is just a kind of bus. Specific PCI devices can be character devices, network devices, USB host controllers, etc. Therefore, a device driver that is specifically connected to the system through the PCI bus contains at least two parts: the PCI device driver and the driver of the device itself. The PCI driver is only to assist the driver of the device itself. It is not the goal but only a means. The PCI device itself has more than one identity. For example, in the character device driver connected to the system through the PCI bus, in addition to implementing the PCI driver part, the main body is still the driver of the device as a character device itself.
[0055] a) Interrupt service routine design
[0056] The interrupt handling of the PCI serial port device driver is mainly responsible for operations such as identifying interrupts, responding to interrupts, and waking up sleeping processes, and the design is as follows: identifying interrupt resources; responding to interrupt requests; waking up the sleeping process corresponding to the interrupt.
[0057] b) Design of the API interface with the user layer
[0058] In the present invention, the PCI serial port device adopts the character device model. In Linux, a character device is represented by the structure cdev, and its structure definition is as follows:
[0059]
[0060] Among them, the member functions in the file_operations structure are the main content of the character device driver program design.
[0061] Several commonly used member functions of the file_operations structure are: read() is used to read data from the device and calls copy_to_user to copy count kernel data to the user space buf. The read() system call in the application program will call this function; the function write() sends data to the device and calls copy_from_user() to copy count data from the user space buf to the kernel and then send it to the device. The write() system call in the application program will call this function; ioctl() provides the implementation of device-related control commands; open() is the device opening function; release() is the device releasing function. These functions are defined in the driver and the file_operations structure is initialized.
[0062] Opening of the device
[0063] The opening of the device is used to call the UartCard_open() function in the driver program when the application program calls the open() function.
[0064] This function is mainly responsible for increasing the usage count of the device, applying for an interrupt based on the interrupt number, and registering an interrupt handling function.
[0065] Shutdown of the device
[0066] Contrary to the opening of the device, the main work completed during the shutdown of the device is to release the interrupt and reduce the usage count of the module.
[0067] Read operation of the device
[0068] The read operation of the device mainly copies the serial port data from the kernel space to the user space for use by the user process. The specific implementation is as follows:
[0069] 1) Wait for data to be read;
[0070] 2) Copy the data in the device to the kernel space;
[0071] 3) Copy the data from the kernel space to the user space.
[0072] Write operation of the device
[0073] The write operation of the device mainly copies the data from the user process to the kernel process, and then writes the data in the kernel space to the I / O memory of the PCI device. The specific implementation is as follows:
[0074] 1) Copy the data from the user space to the kernel space;
[0075] 2) Copy the data in the kernel space to the device memory.
[0076] After completing these tasks, the initialization and registration of the device are completed in the probe() function, including the allocation of the device number and the application for interrupts.
[0077] Step 6: Bind the interrupt to the specified CPU.
[0078] Frequent generation of hardware interrupts is a very CPU-consuming task. Since all PCI interrupts on the Loongson platform share the same PCIE interrupt, interrupt number 100, this will result in a particularly heavy load on CPU0, while the load on CPUs 2-3 is low, leading to a reduction in system performance. To solve this problem, the SMP IRQ Affinity technology is adopted to bind the interrupt number of the PCI serial port device to CPU2, effectively improving the utilization rate of system resources. The specific operations are as follows:
[0079] 1) Stop the service process for automatic IRQ adjustment;
[0080] 2) Manually bind the IRQ to CPU2.
[0081] It should be emphasized that the embodiments described in the present invention are illustrative rather than restrictive. Therefore, the present invention includes, but is not limited to, the embodiments described in the specific embodiments. Any other embodiments obtained by those skilled in the art based on the technical solutions of the present invention also fall within the scope of protection of the present invention.
Claims
1. PCI serial port device universal driver system based on Loongson platform, characterized by: It includes a Loongson processor 3A3000, a Loongson bridge chip 7A1000 and a PCIE to PCI bridge chip, wherein the Loongson processor 3A3000 and the Loongson bridge chip 7A1000 are connected to each other, the PCIE interface of the Loongson bridge chip 7A1000 is connected to the input end of the PCIE to PCI bridge chip, the output end of the PCIE to PCI bridge chip is connected to the PCI devices respectively, and all PCI devices are connected to the adapter bridge chip and share the same interrupt.
2. A configuration method for a universal driver system for PCI serial port devices based on a Loongson platform as claimed in claim 1, characterized in that: The following steps are involved: Step 1. Configure PC device space; Step 2: The kernel initializes the PCI device and generates the pci_dev structure diagram; Step 3: According to the generated pci_dev structure diagram, load the driver and call the pci_dev member; Step 4: Detect the corresponding pci_dev through probe() and provide the corresponding information to the PCI device driver; Step 5: Implement the PCI device as a character device driver; Step 6: Bind the interrupt to the specified CPU.
3. The configuration method of the universal driver system for PCI serial port devices based on the Loongson platform according to claim 2, characterized in that: The specific implementation method of step 3 is: use pci_driver to define the PCI driver, pci_driver includes functions such as detection / removal, suspend / resume of PCI devices; and also involves four important structure members: device name, device list, device search function and device removal function.
4. The configuration method of the universal driver system for PCI serial port devices based on the Loongson platform according to claim 2, characterized in that: The specific implementation method of step 4 is: the member function probe() detects the PCI device according to the device list defined by the structpci_dev_id structure, and saves the configuration information to the parameter pci_dev; in the probe() function, the initialization of the PCI device and the registration of its own device identity driver must be completed.
5. The configuration method of the PCI serial port device universal driver system based on the Loongson platform according to claim 2, characterized in that: The specific implementation method of step 6 is: Step 6.1, interrupt service program design: The interrupt processing of the PCI serial port device driver is mainly responsible for identifying interrupts, responding to interrupts and waking up sleeping process operations, including: identifying interrupt resources; responding to interrupt requests; waking up the sleeping process corresponding to the interrupt; Step 6.2, design of user layer API interface: PCI serial port device adopts character device model. In Linux, a character device is represented by structure cdev, and its structure definition is as follows: The member functions in the file_operations structure are the main content of the character device driver design; The commonly used member functions of the file_operations structure are: read() is used to read data from the device, call copy_to_user to copy count kernel data to user space buf, and the read() system call in the application will call this function back; the write() function sends data to the device, calls copy_from_user() to copy count data from user space buf to the kernel and then sends it to the device, and the write() system call in the application will call this function back; ioctl() provides the implementation of device-related control commands; open() device opening function; release() device release function; define these functions in the driver and initialize the file_operations structure.
Citation Information
Cited By
Universal configurable multifunctional PCIe device driving system
CN121501709A