3 * ________ _________ ____ / __ \/ ___/
4 * / ___/ _ \/ ___/ __ \/ __ \/ / / /\__ \
5 * / / / __/ /__/ /_/ / / / / /_/ /___/ /
6 * /_/ \___/\___/\____/_/ /_/\____//____/
8 * ======================================================================
10 * title: Architecture specific code - Zynq, Linux
13 * author: Christoph RĂ¼thing, University of Paderborn
14 * description: Functions needed for ReconOS which are architecure
15 * specific and are implemented here.
17 * ======================================================================
21 #ifdef RECONOS_ARCH_zynq
22 #ifdef RECONOS_OS_linux
26 #include "../../linux/driver/include/reconos.h"
31 #include <sys/ioctl.h>
34 #define PROC_CONTROL_DEV "/dev/reconos-proc-control"
35 #define OSIF_DEV "/dev/reconos-osif-%d"
38 /* == OSIF related functions ============================================ */
40 int reconos_osif_open(int num
) {
47 snprintf(dev
, 25, OSIF_DEV
, num
);
48 fd
= open(dev
, O_RDWR
);
50 panic("[reconos_core] error while opening osif %d\n", num
);
55 uint32_t reconos_osif_read(int fd
) {
59 ret
= read(fd
, &data
, sizeof(data
));
61 panic("[reconos-core] error reading from osif\n");
66 void reconos_osif_write(int fd
, uint32_t data
) {
69 ret
= write(fd
, &data
, sizeof(data
));
71 panic("[reconos-core] error writing to osif\n");
74 void reconos_osif_close(int fd
) {
79 /* == Proc control related functions ==================================== */
81 int reconos_proc_control_open() {
84 fd
= open(PROC_CONTROL_DEV
, O_RDWR
);
86 panic("[reconos_core] error while opening proc control\n");
91 int reconos_proc_control_get_num_hwts(int fd
) {
94 ioctl(fd
, RECONOS_PROC_CONTROL_GET_NUM_HWTS
, &data
);
99 int reconos_proc_control_get_tlb_hits(int fd
) {
102 ioctl(fd
, RECONOS_PROC_CONTROL_GET_TLB_HITS
, &data
);
107 int reconos_proc_control_get_tlb_misses(int fd
) {
110 ioctl(fd
, RECONOS_PROC_CONTROL_GET_TLB_MISSES
, &data
);
115 uint32_t reconos_proc_control_get_fault_addr(int fd
) {
118 ioctl(fd
, RECONOS_PROC_CONTROL_GET_FAULT_ADDR
, &data
);
123 void reconos_proc_control_clear_page_fault(int fd
) {
124 ioctl(fd
, RECONOS_PROC_CONTROL_CLEAR_PAGE_FAULT
, NULL
);
127 void reconos_proc_control_set_pgd(int fd
) {
128 ioctl(fd
, RECONOS_PROC_CONTROL_SET_PGD_ADDR
, NULL
);
131 void reconos_proc_control_sys_reset(int fd
) {
132 ioctl(fd
, RECONOS_PROC_CONTROL_SYS_RESET
, NULL
);
135 void reconos_proc_control_hwt_reset(int fd
, int num
, int reset
) {
137 ioctl(fd
, RECONOS_PROC_CONTROL_SET_HWT_RESET
, &num
);
139 ioctl(fd
, RECONOS_PROC_CONTROL_CLEAR_HWT_RESET
, &num
);
142 void reconos_proc_control_cache_flush(int fd
) {
143 ioctl(fd
, RECONOS_PROC_CONTROL_CACHE_FLUSH
, NULL
);
146 void reconos_proc_control_close(int fd
) {
151 /* == Reconfiguration related functions ================================= */
153 int is_configured
= 0;
154 pthread_mutex_t mutex
;
156 inline void init_xdevcfg() {
157 if (!is_configured
) {
158 pthread_mutex_init(&mutex
, NULL
);
163 int load_partial_bitstream(uint32_t *bitstream
, unsigned int bitstream_length
) {
169 //printf("... Programming FPGA with partial bitstream\n");
170 //printf("... Bitstream has size of %d bytes and begins with 0x%x 0x%x 0x%x\n", bitstream_length * 4, bitstream[0], bitstream[1], bitstream[2]);
172 pthread_mutex_lock(&mutex
);
174 fd
= open("/sys/class/xdevcfg/xdevcfg/device/is_partial_bitstream", O_WRONLY
);
176 printf("[xdevcfg lib] failed to open\n");
182 fd
= open("/dev/xdevcfg", O_WRONLY
);
184 printf("[xdevcfg lib] failed to open\n");
187 write(fd
, bitstream
, bitstream_length
* 4);
190 fd
= open("/sys/class/xdevcfg/xdevcfg/device/prog_done", O_RDONLY
);
192 printf("[xdevcfg lib] failed to open\n");
197 //printf("... Waiting for programming to finish, currently reading %c\n", d);
201 pthread_mutex_unlock(&mutex
);
207 /* == Initialization function =========================================== */
209 void reconos_drv_init() {
210 // nothing to do here