fmc-chardev.txt 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. fmc-chardev
  2. ===========
  3. This is a simple generic driver, that allows user access by means of a
  4. character device (actually, one for each mezzanine it takes hold of).
  5. The char device is created as a misc device. Its name in /dev (as
  6. created by udev) is the same name as the underlying FMC device. Thus,
  7. the name can be a silly fmc-0000 look-alike if the device has no
  8. identifiers nor bus_id, a more specific fmc-0400 if the device has a
  9. bus-specific address but no associated name, or something like
  10. fdelay-0400 if the FMC core can rely on both a mezzanine name and a bus
  11. address.
  12. Currently the driver only supports read and write: you can lseek to the
  13. desired address and read or write a register.
  14. The driver assumes all registers are 32-bit in size, and only accepts a
  15. single read or write per system call. However, as a result of Unix read
  16. and write semantics, users can simply fread or fwrite bigger areas in
  17. order to dump or store bigger memory areas.
  18. There is currently no support for mmap, user-space interrupt management
  19. and DMA buffers. They may be added in later versions, if the need
  20. arises.
  21. The example below shows raw access to a SPEC card programmed with its
  22. golden FPGA file, that features an SDB structure at offset 256 - i.e.
  23. 64 words. The mezzanine's EEPROM in this case is not programmed, so the
  24. default name is fmc-<bus><devfn>, and there are two cards in the system:
  25. spusa.root# insmod fmc-chardev.ko
  26. [ 1073.339332] spec 0000:02:00.0: Driver has no ID: matches all
  27. [ 1073.345051] spec 0000:02:00.0: Created misc device "fmc-0200"
  28. [ 1073.350821] spec 0000:04:00.0: Driver has no ID: matches all
  29. [ 1073.356525] spec 0000:04:00.0: Created misc device "fmc-0400"
  30. spusa.root# ls -l /dev/fmc*
  31. crw------- 1 root root 10, 58 Nov 20 19:23 /dev/fmc-0200
  32. crw------- 1 root root 10, 57 Nov 20 19:23 /dev/fmc-0400
  33. spusa.root# dd bs=4 skip=64 count=1 if=/dev/fmc-0200 2> /dev/null | od -t x1z
  34. 0000000 2d 42 44 53 >-BDS<
  35. 0000004
  36. The simple program tools/fmc-mem in this package can access an FMC char
  37. device and read or write a word or a whole area. Actually, the program
  38. is not specific to FMC at all, it just uses lseek, read and write.
  39. Its first argument is the device name, the second the offset, the third
  40. (if any) the value to write and the optional last argument that must
  41. begin with "+" is the number of bytes to read or write. In case of
  42. repeated reading data is written to stdout; repeated writes read from
  43. stdin and the value argument is ignored.
  44. The following examples show reading the SDB magic number and the first
  45. SDB record from a SPEC device programmed with its golden image:
  46. spusa.root# ./fmc-mem /dev/fmc-0200 100
  47. 5344422d
  48. spusa.root# ./fmc-mem /dev/fmc-0200 100 +40 | od -Ax -t x1z
  49. 000000 2d 42 44 53 00 01 02 00 00 00 00 00 00 00 00 00 >-BDS............<
  50. 000010 00 00 00 00 ff 01 00 00 00 00 00 00 51 06 00 00 >............Q...<
  51. 000020 c9 42 a5 e6 02 00 00 00 11 05 12 20 2d 34 42 57 >.B......... -4BW<
  52. 000030 73 6f 72 43 72 61 62 73 49 53 47 2d 00 20 20 20 >sorCrabsISG-. <
  53. 000040