Associate an existing Linux device structure with a device file

I am developing a PowerPC 405 built into the Virtex4 FPGA with the Linux 2.6.33 kernel.

So far, I have written drivers for platform devices implemented in FPGAs as loadable kernel modules. Devices are registered using the Open Open Firmware Device Tree file. To create a device file, I use the OF functions to get the node device and then register a new miscdevice , which then automatically registers the minor device number and creates a device file for it. This also creates a device built into miscdevice (i.e. miscdevice.this_device )

Now the problem is DMA operations. I tried to call the dma_alloc_coherent() function using miscdevice.this_device , but this device is not connected to any bus and always returns an error. I did something, and it turned out that the struct of_device also has a struct device built into it (i.e. of_device.dev ). When I tried using this with dma_alloc_coherent() , it worked fine.

So now I have two different struct device structures, one for managing a personal device file, and the other for managing basic Open Firmware system calls, bus transactions, and DMA. These devices are not connected to each other in sysfs, of course.

My question is: can I somehow request to create a device file for the device structure that I get from the OF level and not create a new device with the Misc API? Thus, everything will be connected with one device structure.

+4
source share
1 answer

I think your fix on dma_alloc_coherent () is correct.

But I don’t think it’s wrong to use the device structure built into the of_device structure to replace the created miscdevice. The of_device parameter is a description of objects in the Open Firmware database. And, according to the Linux device driver model, the device structure is embedded in various device objects in the Linux kernel. And I think that you are registering miscdevice as a single character device, the file_operations structure should be connected.

In one word, they have different views, and they cannot replace each other.

+3
source

Source: https://habr.com/ru/post/1483680/


All Articles