/alps/pcitool

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/pcitool
227 by Suren A. Chilingaryan
Initial implementation of IPEDMA, dummy driver for KAPTURE, start of API changes
1
#ifndef _PCILIB_DMA_IPE_PRIVATE_H
2
#define _PCILIB_DMA_IPE_PRIVATE_H
3
236 by Suren A. Chilingaryan
Big redign of model structures
4
#include "dma.h"
5
278 by Suren A. Chilingaryan
Use 64-bit addressing in IPEDMA only for gen3 boards or if enforced
6
//#define IPEDMA_ENFORCE_64BIT_MODE	1		/**< enforce 64-bit mode addressing (otherwise it is used only if register 0x18 specifies PCIe gen3 as required by DMA engine) */
227 by Suren A. Chilingaryan
Initial implementation of IPEDMA, dummy driver for KAPTURE, start of API changes
7
#define IPEDMA_CORES			1
268 by Suren A. Chilingaryan
Dynamicly set TLP(Payload) size in IPEDMA
8
#define IPEDMA_MAX_TLP_SIZE		256		/**< Defines maximum TLP in bytes supported by device */
278 by Suren A. Chilingaryan
Use 64-bit addressing in IPEDMA only for gen3 boards or if enforced
9
//#define IPEDMA_TLP_SIZE			128		/**< If set, enforces the specified TLP size */
268 by Suren A. Chilingaryan
Dynamicly set TLP(Payload) size in IPEDMA
10
293 by Suren A. Chilingaryan
Detect if IPEDMA operates in streaming mode
11
#define IPEDMA_STREAMING_MODE				/**< Enables streaming DMA operation mode instead of ring-buffer, the page is written once and forgotten and need to be pushed in queue again */
296 by Suren A. Chilingaryan
Disable STREAMING_CHECKS for better performance
12
//#define IPEDMA_STREAMING_CHECKS				/**< Enables status checks in streaming mode (it will cause _significant_ performance penalty, max ~ 2 GB/s) */
227 by Suren A. Chilingaryan
Initial implementation of IPEDMA, dummy driver for KAPTURE, start of API changes
13
#define IPEDMA_DMA_PROGRESS_THRESHOLD	1		/**< how many pages the DMA engine should fill before reporting progress */
14
#define IPEDMA_DESCRIPTOR_SIZE		128
15
#define IPEDMA_DESCRIPTOR_ALIGNMENT	64
16
268 by Suren A. Chilingaryan
Dynamicly set TLP(Payload) size in IPEDMA
17
18
//#define IPEDMA_BUG_LAST_READ				/**< We should forbid writting the second last available DMA buffer (the last is forbidden by design) */
19
//#define IPEDMA_DETECT_PACKETS				/**< Using empty_deceted flag */
335 by Suren A. Chilingaryan
Enforce 64-bit dma mask from IPEDMA if supported
20
#define IPEDMA_SUPPORT_EMPTY_DETECTED			/**< Avoid waiting for data when empty_detected flag is set in hardware */
21
#define IPEDMA_CONFIGURE_DMA_MASK			/**< Enforce maximal DMA mask (to avoid bounce-buffers) */
268 by Suren A. Chilingaryan
Dynamicly set TLP(Payload) size in IPEDMA
22
333 by Suren A. Chilingaryan
Adjust IPEDMA register model to address new revision
23
#define IPEDMA_REG_ADDR_MASK 0xFFF
24
#define IPEDMA_REG_BANK_MASK 0xF000
334 by Suren A. Chilingaryan
Support 64-bit addressing mode in IPEDMA
25
#define IPEDMA_REG_BANK_SHIFT 12
333 by Suren A. Chilingaryan
Adjust IPEDMA register model to address new revision
26
27
#define REG2VIRT(reg) (ctx->base_addr[(reg&IPEDMA_REG_BANK_MASK)>>IPEDMA_REG_BANK_SHIFT] + (reg&IPEDMA_REG_ADDR_MASK))
28
#define REG(bank, addr) ((bank<<IPEDMA_REG_BANK_SHIFT)|addr)
29
#define CONFREG(addr) REG(2, addr)
30
378 by Suren A. Chilingaryan
New IPEDMA versioning
31
#define IPEDMA_REG_VERSION		0x18
32
#define IPEDMA_REG_APPVERSION		REG(1, 0x20)
33
#define IPEDMA_GENERATION(ver)          (ver&0xF)
34
#define IPEDMA_STREAMING(ver)           ((ver>>4)&0x1)
35
#define IPEDMA_VERSION(ver)             ((ver>>16)&0xFFFF)
262 by Suren A. Chilingaryan
Support gen3 DMA engine and provide work-arround for hardware mishandling last_descriptor_read register
36
227 by Suren A. Chilingaryan
Initial implementation of IPEDMA, dummy driver for KAPTURE, start of API changes
37
#define IPEDMA_REG_RESET		0x00
38
#define IPEDMA_REG_CONTROL		0x04
39
#define IPEDMA_REG_TLP_SIZE		0x0C
40
#define IPEDMA_REG_TLP_COUNT		0x10
41
#define IPEDMA_REG_UPDATE_THRESHOLD	0x60
274 by Suren A. Chilingaryan
Support streaming mode in IPEDMA
42
#define IPEDMA_REG_STREAMING_STATUS	0x68
43
333 by Suren A. Chilingaryan
Adjust IPEDMA register model to address new revision
44
    // PCIe gen2
45
#define IPEDMA_REG2_PAGE_ADDR		0x50
46
#define IPEDMA_REG2_UPDATE_ADDR		0x54
47
#define IPEDMA_REG2_LAST_READ		0x58		/**< In streaming mode, we can use it freely to track current status */
48
#define IPEDMA_REG2_PAGE_COUNT		0x5C
49
50
    // PCIe gen3
51
#define IPEDMA_REG3_PAGE_COUNT		0x40		/**< Read-only now */
52
#define IPEDMA_REG3_PAGE_ADDR		0x50
53
#define IPEDMA_REG3_UPDATE_ADDR		0x58
54
#define IPEDMA_REG3_LAST_READ		CONFREG(0x80)
55
56
329 by Suren A. Chilingaryan
IPEDMA Update
57
#define IPEDMA_FLAG_NOSYNC		0x01		/**< Do not call kernel space for page synchronization */
58
#define IPEDMA_FLAG_NOSLEEP		0x02		/**< Do not sleep in the loop while waiting for the data */
59
378 by Suren A. Chilingaryan
New IPEDMA versioning
60
//#define IPEDMA_MASK_PCIE_GEN		0xF
61
//#define IPEDMA_MASK_STREAMING_MODE	0x10
293 by Suren A. Chilingaryan
Detect if IPEDMA operates in streaming mode
62
329 by Suren A. Chilingaryan
IPEDMA Update
63
#define IPEDMA_RESET_DELAY		10000		/**< Sleep between accessing DMA control and reset registers */
64
#define IPEDMA_ADD_PAGE_DELAY		1000		/**< Delay between submitting successive DMA pages into IPEDMA_REG_PAGE_ADDR register */
65
#define IPEDMA_NODATA_SLEEP		100		/**< To keep CPU free, in nanoseconds */
66
227 by Suren A. Chilingaryan
Initial implementation of IPEDMA, dummy driver for KAPTURE, start of API changes
67
333 by Suren A. Chilingaryan
Adjust IPEDMA register model to address new revision
68
#define WR(addr, value) { *(uint32_t*)(REG2VIRT(addr)) = value; }
69
#define RD(addr, value) { value = *(uint32_t*)(REG2VIRT(addr)); }
265 by Suren A. Chilingaryan
Add fields reporting consumed buffers and space to the dma_engine_status and provide better ipedma benchmarking
70
334 by Suren A. Chilingaryan
Support 64-bit addressing mode in IPEDMA
71
#define WR64(addr, value) { *(uint64_t*)(REG2VIRT(addr)) = value; }
72
#define RD64(addr, value) { value = *(uint64_t*)(REG2VIRT(addr)); }
73
390 by Suren A. Chilingaryan
Crticial fix in IPEDMA resulting in spurious data generated, due to not finished migration to new versioning scheme in hardware
74
#define DEREF(ptr) ((ctx->addr64)?(*(uint64_t*)ptr):(*(uint32_t*)ptr))
334 by Suren A. Chilingaryan
Support 64-bit addressing mode in IPEDMA
75
76
typedef uint32_t reg_t;
227 by Suren A. Chilingaryan
Initial implementation of IPEDMA, dummy driver for KAPTURE, start of API changes
77
typedef struct ipe_dma_s ipe_dma_t;
78
79
struct ipe_dma_s {
236 by Suren A. Chilingaryan
Big redign of model structures
80
    pcilib_dma_context_t dmactx;
81
    //pcilib_dma_engine_description_t engine[2];
227 by Suren A. Chilingaryan
Initial implementation of IPEDMA, dummy driver for KAPTURE, start of API changes
82
236 by Suren A. Chilingaryan
Big redign of model structures
83
    const pcilib_register_bank_description_t *dma_bank;
333 by Suren A. Chilingaryan
Adjust IPEDMA register model to address new revision
84
    char *base_addr[3];
227 by Suren A. Chilingaryan
Initial implementation of IPEDMA, dummy driver for KAPTURE, start of API changes
85
86
    pcilib_irq_type_t irq_enabled;	/**< indicates that IRQs are enabled */
87
    pcilib_irq_type_t irq_preserve;	/**< indicates that IRQs should not be disabled during clean-up */
88
    int irq_started;			/**< indicates that IRQ subsystem is initialized (detecting which types should be preserverd) */    
89
378 by Suren A. Chilingaryan
New IPEDMA versioning
90
    uint32_t gen;                       /**< hardware generation, currently corresponds to PCIe generation 2/3 */
91
    uint32_t version;			/**< hardware revision */
92
    int mode64;				/**< indicates 64-bit operation mode (for gen2, gen3 always operates in 64-bit mode) */
93
    int addr64;                         /**< indicates that 64-bit addressing mode is used (gen3 only) */
94
    int streaming;			/**< indicates if DMA is operating in streaming or ring-buffer mode (gen3 only) */
95
227 by Suren A. Chilingaryan
Initial implementation of IPEDMA, dummy driver for KAPTURE, start of API changes
96
    int started;			/**< indicates that DMA buffers are initialized and reading is allowed */
97
    int writting;			/**< indicates that we are in middle of writting packet */
98
    int reused;				/**< indicates that DMA was found intialized, buffers were reused, and no additional initialization is needed */
99
    int preserve;			/**< indicates that DMA should not be stopped during clean-up */
100
329 by Suren A. Chilingaryan
IPEDMA Update
101
    uint32_t dma_flags;			/**< Various operation flags, see IPEDMA_FLAG_* */
102
    size_t dma_timeout;			/**< DMA timeout,IPEDMA_DMA_TIMEOUT is used by default */
103
    size_t dma_pages;			/**< Number of DMA pages in ring buffer to allocate */
104
227 by Suren A. Chilingaryan
Initial implementation of IPEDMA, dummy driver for KAPTURE, start of API changes
105
    pcilib_kmem_handle_t *desc;		/**< in-memory status descriptor written by DMA engine upon operation progess */
106
    pcilib_kmem_handle_t *pages;	/**< collection of memory-locked pages for DMA operation */
107
342 by Suren A. Chilingaryan
Support large DMA pages in IPEDMA
108
    size_t ring_size, page_size;	/**< Number of pages in ring buffer and the size of a single DMA page */
334 by Suren A. Chilingaryan
Support 64-bit addressing mode in IPEDMA
109
    size_t last_read, last_written;
110
    uintptr_t last_read_addr;
227 by Suren A. Chilingaryan
Initial implementation of IPEDMA, dummy driver for KAPTURE, start of API changes
111
334 by Suren A. Chilingaryan
Support 64-bit addressing mode in IPEDMA
112
    reg_t reg_last_read;		/**< actual location of last_read register (removed from hardware for version 3) */
227 by Suren A. Chilingaryan
Initial implementation of IPEDMA, dummy driver for KAPTURE, start of API changes
113
};
114
115
#endif /* _PCILIB_DMA_IPE_PRIVATE_H */