Add RISC-V support.
[fw/openocd] / src / target / riscv / batch.h
1 #ifndef TARGET__RISCV__SCANS_H
2 #define TARGET__RISCV__SCANS_H
3
4 #include "target/target.h"
5 #include "jtag/jtag.h"
6
7 enum riscv_scan_type {
8         RISCV_SCAN_TYPE_INVALID,
9         RISCV_SCAN_TYPE_NOP,
10         RISCV_SCAN_TYPE_READ,
11         RISCV_SCAN_TYPE_WRITE,
12 };
13
14 /* A batch of multiple JTAG scans, which are grouped together to avoid the
15  * overhead of some JTAG adapters when sending single commands.  This is
16  * designed to support block copies, as that's what we actually need to go
17  * fast. */
18 struct riscv_batch {
19         struct target *target;
20
21         size_t allocated_scans;
22         size_t used_scans;
23
24         size_t idle_count;
25
26         uint8_t *data_out;
27         uint8_t *data_in;
28         struct scan_field *fields;
29
30         /* In JTAG we scan out the previous value's output when performing a
31          * scan.  This is a pain for users, so we just provide them the
32          * illusion of not having to do this by eliding all but the last NOP.
33          * */
34         enum riscv_scan_type last_scan;
35
36         /* The read keys. */
37         size_t *read_keys;
38         size_t read_keys_used;
39 };
40
41 /* Allocates (or frees) a new scan set.  "scans" is the maximum number of JTAG
42  * scans that can be issued to this object, and idle is the number of JTAG idle
43  * cycles between every real scan. */
44 struct riscv_batch *riscv_batch_alloc(struct target *target, size_t scans, size_t idle);
45 void riscv_batch_free(struct riscv_batch *batch);
46
47 /* Checks to see if this batch is full. */
48 bool riscv_batch_full(struct riscv_batch *batch);
49
50 /* Executes this scan batch. */
51 int riscv_batch_run(struct riscv_batch *batch);
52
53 /* Adds a DMI write to this batch. */
54 void riscv_batch_add_dmi_write(struct riscv_batch *batch, unsigned address, uint64_t data);
55
56 /* DMI reads must be handled in two parts: the first one schedules a read and
57  * provides a key, the second one actually obtains the value of that read .*/
58 size_t riscv_batch_add_dmi_read(struct riscv_batch *batch, unsigned address);
59 uint64_t riscv_batch_get_dmi_read(struct riscv_batch *batch, size_t key);
60
61 /* Scans in a NOP. */
62 void riscv_batch_add_nop(struct riscv_batch *batch);
63
64 #endif