nmc-utils  0.1.1
easynmc.h
Go to the documentation of this file.
1 #ifndef LIBEASYNMC_H_H
2 #define LIBEASYNMC_H_H
3 
4 #include <stdint.h>
5 #include <libelf.h>
6 #include <gelf.h>
7 #include <sys/file.h>
8 #include <linux/easynmc.h>
9 
10 #define NMC_REG_CODEVERSION (0x100)
11 #define NMC_REG_ISR_ON_START (0x101)
12 #define NMC_REG_CORE_STATUS (0x102)
13 #define NMC_REG_CORE_START (0x103)
14 #define NMC_REG_PROG_ENTRY (0x104)
15 #define NMC_REG_PROG_RETURN (0x105)
16 #define NMC_REG_APPDATA_SIZE (0x106)
17 
18 extern int g_libeasynmc_debug;
19 extern int g_libeasynmc_errors;
20 
21 #define EASYNMC_APPID_LEN 8
22 
23 struct easynmc_handle;
24 
26  const char* name;
27  int (*handle_section)(struct easynmc_handle *h, char* name, FILE *rfd, GElf_Shdr shdr);
29 };
30 
32  int id;
34  int iofd;
35  int memfd;
36  char* imem;
37  uint32_t *imem32;
38  uint32_t imem_size;
39  /* Private data */
41  int argoffset;
43  char *appid;
44 };
45 
46 #ifndef ARRAY_SIZE
47 #define ARRAY_SIZE(a) \
48  (sizeof(a) / sizeof(*(a)))
49 #endif
50 
55  EASYNMC_CORE_PAUSED, /* Reserved, needs bootcode support */
56  EASYNMC_CORE_KILLABLE, /* App can disposed off safely */
58 };
59 
63 };
64 
65 #define ABSLOAD_FLAG_FORCE (1<<0)
66 #define ABSLOAD_FLAG_STDIO (1<<1)
67 #define ABSLOAD_FLAG_ARGS (1<<2)
68 #define ABSLOAD_FLAG_SYNCLIB (1<<3)
69 
70 #define EASYNMC_ITERATE_STOP (1<<0)
71 #define EASYNMC_ITERATE_NOCLOSE (1<<1)
72 
73 #define ABSLOAD_FLAG_DEFAULT \
74  (ABSLOAD_FLAG_STDIO | ABSLOAD_FLAG_ARGS)
75 
76 struct easynmc_token {
77  struct nmc_irq_token tok;
78  struct easynmc_handle *h;
79 };
80 
81 #define EASYNMC_CORE_ANY -1
82 
83 
84 struct easynmc_handle *easynmc_open(int coreid);
85 struct easynmc_handle *easynmc_open_noboot(int coreid, int exclusive);
86 void easynmc_close(struct easynmc_handle *hndl);
87 
88 int easynmc_boot_core(struct easynmc_handle *h, int debug);
89 
90 int easynmc_reset_stats(struct easynmc_handle *h);
91 
93 const char* easynmc_state_name(enum easynmc_core_state state);
94 
95 int easynmc_load_abs(struct easynmc_handle *h, const char *path, uint32_t* ep, int flags);
96 int easynmc_set_args(struct easynmc_handle *h, char* self, int argc, char **argv);
97 int easynmc_start_app(struct easynmc_handle *h, uint32_t entry);
98 char *easynmc_get_default_ipl(char* name, int debug);
99 
100 int easynmc_stop_app(struct easynmc_handle *h);
101 int easynmc_exitcode(struct easynmc_handle *h);
102 
103 
104 struct easynmc_token *easynmc_token_new(struct easynmc_handle *h, uint32_t events);
105 int easynmc_token_clear(struct easynmc_token *t);
106 int easynmc_token_wait(struct easynmc_token *t, uint32_t timeout);
108 
109 int easynmc_pollmark(struct easynmc_handle *h);
110 
111 /* Section filters are a quick way to add your own ways of handling stuff */
112 
113 /* Low-level stuff, normally you won't need those */
114 int easynmc_send_irq(struct easynmc_handle *h, enum nmc_irq irq);
115 int easynmc_startupcode_is_compatible(uint32_t codever);
116 int easynmc_get_core_name(struct easynmc_handle *h, char* str);
117 int easynmc_get_core_type(struct easynmc_handle *h, char* str);
118 const char* easynmc_evt_name(int evt);
119 
120 
123 
124 
125 /* Persistence */
126 struct easynmc_handle *easynmc_connect(const char *appid);
127 const char *easynmc_appid_get(struct easynmc_handle *h);
128 int easynmc_appid_set(struct easynmc_handle *h, char appid[]);
129 size_t easynmc_appdata_get(struct easynmc_handle *h, void *data, size_t len);
130 int easynmc_appdata_set(struct easynmc_handle *h, void *data, size_t len);
131 int easynmc_for_each_core(int (*core_cb)(struct easynmc_handle *h, void *udata), int exclusive, void *udata);
132 int easynmc_persist_set(struct easynmc_handle *h, enum easynmc_persist_state status);
133 
134 #endif