bar.h 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef _PCILIB_BAR_H
  2. #define _PCILIB_BAR_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /**
  7. * Detects in which PCI BAR the specified buffer is residing. The complete specified buffer
  8. * of \a size bytes should fit into the BAR. Otherwise, an error will be returned.
  9. * @param[in] ctx - pcilib context
  10. * @param[in] addr - physical address of the begining of the buffer
  11. * @param[in] size - the size of the buffer
  12. * @return - return the BAR (numbered from 0) or PCILIB_BAR_INVALID if buffer does not belong to any BAR.
  13. */
  14. pcilib_bar_t pcilib_detect_bar(pcilib_t *ctx, uintptr_t addr, size_t size);
  15. /**
  16. * Maps the specified bar to the address space of the process. This function may be called multiple times for
  17. * the same bar. It will only map the BAR once. Normally, the required BARs will be automatically mapped when
  18. * BAR addresses are resolved with pcilib_resolve_bar_address() and similar.
  19. * @param[in,out] ctx - pcilib context
  20. * @param[in] bar - the PCI BAR number (numbered from 0)
  21. * return - the address where the BAR is mapped. You can't use this address directly,
  22. * instead pcilib_resolve_register_address(ctx, bar, 0) have to be used to find
  23. * the start of the BAR in virtual address space.
  24. */
  25. void *pcilib_map_bar(pcilib_t *ctx, pcilib_bar_t bar);
  26. /**
  27. * Unmaps the specified bar from the address space of the process. Actually, it will only unmap the BAR if it is
  28. * not used by DMA or Event egines. So, it is fine to include the calls to pcilib_map_bar() / pcilib_unmap_bar()
  29. * when a specific BAR is needed. On other hand, there is a little point in doing so. The BAR may be left mapped
  30. * and will be automatically umapped when pcilib_close() is called.
  31. * @param[in,out] ctx - pcilib context
  32. * @param[in] bar - BAR number (numbered from 0)
  33. * @param[in,out] data - The address returned by pcilib_map_bar() call
  34. */
  35. void pcilib_unmap_bar(pcilib_t *ctx, pcilib_bar_t bar, void *data);
  36. /**
  37. * Detects the BAR and mapping offset of the specified PCI buffer. The complete specified buffer
  38. * of \a size bytes should fit into the BAR. Otherwise, an error will be returned.
  39. * @param[in] ctx - pcilib context
  40. * @param[in,out] bar - the function will check if the buffer belongs to the specified BAR unless bar is PCILIB_BAR_DETECT.
  41. * It will be set to the actually detected BAR in the last case.
  42. * @param[in,out] addr - specifies the address to detect. The address may be specified as absolute physical address or offset in the BAR.
  43. * On success, the addr will contain offset which should be added to the address returned by pcilib_map_bar()
  44. * to get position of BAR mapping in virtual address space.
  45. * @param[in] size - the size of the buffer
  46. * @return - error code or 0 in case of success
  47. */
  48. int pcilib_detect_address(pcilib_t *ctx, pcilib_bar_t *bar, uintptr_t *addr, size_t size);
  49. /**
  50. * Resolves the virtual address and the size of PCI BAR space used for data exchange.
  51. * This is left-over from older version of pcilib and currently unused. We may reconsider
  52. * how it is organized and implemented. The data_space parameter may go into the model definition.
  53. * @param[in] ctx - pcilib context
  54. * @param[in] addr - may hint there the data space is located, use 0 to autodetect
  55. * @param[out] size - the size of data space is returned
  56. * @return - virtual address of data space (ready to use) or NULL if detection has failed
  57. */
  58. char *pcilib_resolve_data_space(pcilib_t *ctx, uintptr_t addr, size_t *size);
  59. /**
  60. * The wrapper arround pcilib_resolve_bar_address() provided for backward compatibility.
  61. * If bar is not specified, it first checks the first BAR with registers, before searching
  62. * in other available BARs.
  63. * @param[in,out] ctx - pcilib context
  64. * @param[in] bar - specifies the BAR address belong to, use PCILIB_BAR_DETECT for autodetection
  65. * @param[in] addr - specifies the physical address on the PCI bus or offset in the BAR if \a bar is specified
  66. * @return - the virtual address in the process address space or NULL in case of error
  67. */
  68. char *pcilib_resolve_register_address(pcilib_t *ctx, pcilib_bar_t bar, uintptr_t addr);
  69. #ifdef __cplusplus
  70. }
  71. #endif
  72. #endif /* _PCILIB_BAR_H */