/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool
258 by Suren A. Chilingaryan
Split bar manipulation and fifo operations in stand-alone source and publish kmem and bar headers
1
#ifndef _PCILIB_BAR_H
2
#define _PCILIB_BAR_H
3
331 by Suren A. Chilingaryan
Provide pcilib_get_bar_info & pcilib_get_bar_list API calls, remove obsolete pcilib_resolve_register_address
4
5
typedef struct {
6
    pcilib_bar_t bar;
7
    size_t size;
8
    uintptr_t phys_addr;
9
    void *virt_addr;
10
} pcilib_bar_info_t;
11
12
277 by Suren A. Chilingaryan
Keep C++ compilers happy
13
#ifdef __cplusplus
14
extern "C" {
15
#endif
16
324 by Suren A. Chilingaryan
Documentation update
17
/**
18
 * Detects in which PCI BAR the specified buffer is residing. The complete specified buffer
19
 * of \a size bytes should fit into the BAR. Otherwise, an error will be returned.
20
 * @param[in] ctx	- pcilib context
21
 * @param[in] addr	- physical address of the begining of the buffer
22
 * @param[in] size	- the size of the buffer
23
 * @return		- return the BAR (numbered from 0) or PCILIB_BAR_INVALID if buffer does not belong to any BAR.
24
 */
258 by Suren A. Chilingaryan
Split bar manipulation and fifo operations in stand-alone source and publish kmem and bar headers
25
pcilib_bar_t pcilib_detect_bar(pcilib_t *ctx, uintptr_t addr, size_t size);
324 by Suren A. Chilingaryan
Documentation update
26
27
/**
28
 * Maps the specified bar to the address space of the process. This function may be called multiple times for 
29
 * the same bar. It will only map the BAR once. Normally, the required BARs will be automatically mapped when
30
 * BAR addresses are resolved with pcilib_resolve_bar_address() and similar.
31
 * @param[in,out] ctx 	- pcilib context
32
 * @param[in] bar	- the PCI BAR number (numbered from 0)
33
 * return 		- the address where the BAR is mapped. You can't use this address directly, 
34
 *			instead pcilib_resolve_register_address(ctx, bar, 0) have to be used to find 
35
 *			the start of the BAR in virtual address space.
36
 */
37
void *pcilib_map_bar(pcilib_t *ctx, pcilib_bar_t bar);
38
39
/**
40
 * Unmaps the specified bar from the address space of the process. Actually, it will only unmap the BAR if it is 
41
 * not used by DMA or Event egines. So, it is fine to include the calls to pcilib_map_bar() / pcilib_unmap_bar() 
42
 * when a specific BAR is needed. On other hand, there is a little point in doing so. The BAR may be left mapped
43
 * and will be automatically umapped when pcilib_close() is called.
44
 * @param[in,out] ctx	- pcilib context
45
 * @param[in] bar	- BAR number (numbered from 0)
46
 * @param[in,out] data	- The address returned by pcilib_map_bar() call
47
 */
48
void pcilib_unmap_bar(pcilib_t *ctx, pcilib_bar_t bar, void *data);
49
50
/**
51
 * Detects the BAR and mapping offset of the specified PCI buffer. The complete specified buffer
52
 * of \a size bytes should fit into the BAR. Otherwise, an error will be returned.
53
 * @param[in] ctx	- pcilib context
54
 * @param[in,out] bar	- the function will check if the buffer belongs to the specified BAR unless bar is PCILIB_BAR_DETECT.
55
 *			It will be set to the actually detected BAR in the last case.
56
 * @param[in,out] addr	- specifies the address to detect. The address may be specified as absolute physical address or offset in the BAR.
57
 *			On success, the addr will contain offset which should be added to the address returned by pcilib_map_bar()
58
 *			to get position of BAR mapping in virtual address space.
59
 * @param[in] size	- the size of the buffer
60
 * @return		- error code or 0 in case of success
61
 */
258 by Suren A. Chilingaryan
Split bar manipulation and fifo operations in stand-alone source and publish kmem and bar headers
62
int pcilib_detect_address(pcilib_t *ctx, pcilib_bar_t *bar, uintptr_t *addr, size_t size);
63
324 by Suren A. Chilingaryan
Documentation update
64
/**
65
 * Resolves the virtual address and the size of PCI BAR space used for data exchange.
66
 * This is left-over from older version of pcilib and currently unused. We may reconsider
67
 * how it is organized and implemented. The data_space parameter may go into the model definition.
68
 * @param[in] ctx	- pcilib context
69
 * @param[in] addr	- may hint there the data space is located, use 0 to autodetect
70
 * @param[out] size	- the size of data space is returned
71
 * @return		- virtual address of data space (ready to use) or NULL if detection has failed
72
 */
73
char *pcilib_resolve_data_space(pcilib_t *ctx, uintptr_t addr, size_t *size);
74
361 by Suren A. Chilingaryan
Documentation update
75
/**
76
 * Return information about the specified BAR or NULL if BAR is not present in hardware
77
 * @param[in,out] ctx	- pcilib context
78
 * @param[in] bar	- the PCI BAR number (numbered from 0)
79
 * @return		- pointer to structure describing the specified BAR or NULL in case of error
80
 */
331 by Suren A. Chilingaryan
Provide pcilib_get_bar_info & pcilib_get_bar_list API calls, remove obsolete pcilib_resolve_register_address
81
const pcilib_bar_info_t *pcilib_get_bar_info(pcilib_t *ctx, pcilib_bar_t bar);
361 by Suren A. Chilingaryan
Documentation update
82
83
/**
84
 * Return a list of BAR memory regions available in the hardware. 
85
 * The list is terminated by a dummy BAR description with 0 size.
86
 *
87
 * @param[in,out] ctx	- pcilib context
88
 * @return		- pointer to structure describing the BARs or NULL in case of error
89
 */
331 by Suren A. Chilingaryan
Provide pcilib_get_bar_info & pcilib_get_bar_list API calls, remove obsolete pcilib_resolve_register_address
90
const pcilib_bar_info_t *pcilib_get_bar_list(pcilib_t *ctx);
324 by Suren A. Chilingaryan
Documentation update
91
277 by Suren A. Chilingaryan
Keep C++ compilers happy
92
93
#ifdef __cplusplus
94
}
95
#endif
96
258 by Suren A. Chilingaryan
Split bar manipulation and fifo operations in stand-alone source and publish kmem and bar headers
97
#endif /* _PCILIB_BAR_H */