1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef VCHOST_H
29#define VCHOST_H
30
31#include "vchost_platform_config.h"
32#include "vcfilesys_defs.h"
33#include "interface/vcos/vcos.h" //for VCHPRE_ abd VCHPOST_ macro's for func declaration
34#include "interface/vmcs_host/vc_fileservice_defs.h" // for VC_O_XXX file definitions
35#include "interface/vchi/vchi.h"
36
37#define UNUSED_PARAMETER(x) ((void)(x))/* macro to suppress not use warning */
38
39/*---------------------------------------------------------------------------*/
40/* Byte-swapping, dependent on host's orientation */
41/*---------------------------------------------------------------------------*/
42
43#ifndef VC_HOST_IS_BIG_ENDIAN
44#define VC_HTOV32(val) (val)
45#define VC_HTOV16(val) (val)
46#define VC_VTOH32(val) (val)
47#define VC_VTOH16(val) (val)
48#else
49static unsigned long VC_HTOV32(unsigned long val) {
50 return ((val<<24) | ((val&0xff00)<<8) | ((val>>8)&0xff00) | ((val>>24)&0xff)); }
51static unsigned short VC_HTOV16(unsigned short val) {
52 return ((val<<8)|(val>>8)); }
53static unsigned long VC_VTOH32(unsigned long val) {
54 return ((val<<24) | ((val&0xff00)<<8) | ((val>>8)&0xff00) | ((val>>24)&0xff)); }
55static unsigned short VC_VTOH16(unsigned short val) {
56 return ((val<<8)|(val>>8)); }
57#endif
58
59/*---------------------------------------------------------------------------*/
60/* Host port related functions */
61/*---------------------------------------------------------------------------*/
62
63/* Boot a bin file from flash into RAM. Returns the id of the application running */
64
65VCHPRE_ int VCHPOST_ vc_host_boot(char *cmd_line, void *binimg, int nbytes, int bootloader);
66
67/* Perform any platform specific initialisations. */
68
69VCHPRE_ int VCHPOST_ vc_host_init(void);
70
71/* Read a multiple of 16 bytes from VideoCore. host_addr has no particular alignment,
72 but it is important that it transfers the data in 16-bit chunks if this is possible. */
73
74VCHPRE_ int VCHPOST_ vc_host_read_consecutive(void *host_addr, uint32_t vc_addr, int nbytes, int channel);
75
76#ifdef VC_HOST_IS_BIG_ENDIAN
77// Reads from VideoCore with an implicit swap of each pair of bytes.
78VCHPRE_ int VCHPOST_ vc_host_read_byteswapped(void *host_addr, uint32_t vc_addr, int nbytes, int channel);
79#endif
80
81/* Write a multiple of 16 bytes to VideoCore. host_addr has no particular alignment,
82 but it is important that it transfers the data in 16-bit chunks if this is possible. */
83
84VCHPRE_ int VCHPOST_ vc_host_write_consecutive(uint32_t vc_addr, void *host_addr, int nbytes, int channel);
85
86#ifdef VC_HOST_IS_BIG_ENDIAN
87// Write to VideoCore with an implicit swap of each pair of bytes.
88VCHPRE_ int VCHPOST_ vc_host_write_byteswapped(uint32_t vc_addr, void *host_addr, int nbytes, int channel);
89#endif
90
91/* Send an interrupt to VideoCore. */
92
93VCHPRE_ int VCHPOST_ vc_host_send_interrupt(int channel);
94
95/* Wait for an interrupt from VideoCore. This can return immediately if applications
96 are happy to busy-wait. */
97
98VCHPRE_ int VCHPOST_ vc_host_wait_interrupt(void);
99
100/* Tell the host to act on or ignore interrupts. */
101
102VCHPRE_ void VCHPOST_ vc_host_interrupts(int on);
103
104/* Function called when there is some kind of internal error. Breakpoints can be set on
105 this for debugging. */
106
107VCHPRE_ void VCHPOST_ vc_error(void);
108
109
110/*---------------------------------------------------------------------------*/
111/* Event (interrupt) related functions */
112/*---------------------------------------------------------------------------*/
113
114// Minimum number of event objects an implementation should support.
115// Sufficient for 2 per 8 interfaces/services + 4 others
116#define VC_EVENT_MAX_NUM 20
117
118/* Create (and clear) an event. Returns a pointer to the event object. */
119VCHPRE_ void * VCHPOST_ vc_event_create(void);
120
121/* Wait for an event to be set, blocking until it is set.
122 Only one thread may be waiting at any one time.
123 The event is automatically cleared on leaving this function. */
124VCHPRE_ void VCHPOST_ vc_event_wait(void *sig);
125
126/* Reads the state of an event (for polling systems) */
127VCHPRE_ int VCHPOST_ vc_event_status(void *sig);
128
129/* Forcibly clears any pending event */
130VCHPRE_ void VCHPOST_ vc_event_clear(void *sig);
131
132/* Sets an event - can be called from any thread */
133VCHPRE_ void VCHPOST_ vc_event_set(void *sig);
134
135/* Register the calling task to be notified of an event. */
136VCHPRE_ void VCHPOST_ vc_event_register(void *ievent);
137
138/* Set events to block, stopping polling mode. */
139VCHPRE_ void VCHPOST_ vc_event_blocking(void);
140
141/*---------------------------------------------------------------------------*/
142/* Semaphore related functions */
143/*---------------------------------------------------------------------------*/
144
145// Minimum number of locks an implementation should support.
146
147#define VC_LOCK_MAX_NUM 32
148
149// Create a lock. Returns a pointer to the lock object. A lock is initially available
150// just once.
151
152VCHPRE_ void * VCHPOST_ vc_lock_create(void);
153
154// Obtain a lock. Block until we have it. Locks are not re-entrant for the same thread.
155
156VCHPRE_ void VCHPOST_ vc_lock_obtain(void *lock);
157
158// Release a lock. Anyone can call this, even if they didn't obtain the lock first.
159
160VCHPRE_ void VCHPOST_ vc_lock_release(void *lock);
161
162/*---------------------------------------------------------------------------*/
163/* File system related functions */
164/*---------------------------------------------------------------------------*/
165
166// Initialises the host dependent file system functions for use
167VCHPRE_ void VCHPOST_ vc_hostfs_init(void);
168VCHPRE_ void VCHPOST_ vc_hostfs_exit(void);
169
170// Low level file system functions equivalent to close(), lseek(), open(), read() and write()
171VCHPRE_ int VCHPOST_ vc_hostfs_close(int fildes);
172
173VCHPRE_ long VCHPOST_ vc_hostfs_lseek(int fildes, long offset, int whence);
174
175VCHPRE_ int64_t VCHPOST_ vc_hostfs_lseek64(int fildes, int64_t offset, int whence);
176
177VCHPRE_ int VCHPOST_ vc_hostfs_open(const char *path, int vc_oflag);
178
179VCHPRE_ int VCHPOST_ vc_hostfs_read(int fildes, void *buf, unsigned int nbyte);
180
181VCHPRE_ int VCHPOST_ vc_hostfs_write(int fildes, const void *buf, unsigned int nbyte);
182
183// Ends a directory listing iteration
184VCHPRE_ int VCHPOST_ vc_hostfs_closedir(void *dhandle);
185
186// Formats the drive that contains the given path
187VCHPRE_ int VCHPOST_ vc_hostfs_format(const char *path);
188
189// Returns the amount of free space on the drive that contains the given path
190VCHPRE_ int VCHPOST_ vc_hostfs_freespace(const char *path);
191VCHPRE_ int64_t VCHPOST_ vc_hostfs_freespace64(const char *path);
192
193// Gets the attributes of the named file
194VCHPRE_ int VCHPOST_ vc_hostfs_get_attr(const char *path, fattributes_t *attr);
195
196// Creates a new directory
197VCHPRE_ int VCHPOST_ vc_hostfs_mkdir(const char *path);
198
199// Starts a directory listing iteration
200VCHPRE_ void * VCHPOST_ vc_hostfs_opendir(const char *dirname);
201
202// Directory listing iterator
203VCHPRE_ struct dirent * VCHPOST_ vc_hostfs_readdir_r(void *dhandle, struct dirent *result);
204
205// Deletes a file or (empty) directory
206VCHPRE_ int VCHPOST_ vc_hostfs_remove(const char *path);
207
208// Renames a file, provided the new name is on the same file system as the old
209VCHPRE_ int VCHPOST_ vc_hostfs_rename(const char *oldfile, const char *newfile);
210
211// Sets the attributes of the named file
212VCHPRE_ int VCHPOST_ vc_hostfs_set_attr(const char *path, fattributes_t attr);
213
214// Truncates a file at its current position
215VCHPRE_ int VCHPOST_ vc_hostfs_setend(int fildes);
216
217// Returns the total amount of space on the drive that contains the given path
218VCHPRE_ int VCHPOST_ vc_hostfs_totalspace(const char *path);
219VCHPRE_ int64_t VCHPOST_ vc_hostfs_totalspace64(const char *path);
220
221// Return millisecond resolution system time, only used for differences
222VCHPRE_ int VCHPOST_ vc_millitime(void);
223
224// Invalidates any cluster chains in the FAT that are not referenced in any directory structures
225VCHPRE_ void VCHPOST_ vc_hostfs_scandisk(const char *path);
226
227// Checks whether or not a FAT filesystem is corrupt or not. If fix_errors is TRUE behaves exactly as vc_filesys_scandisk.
228VCHPRE_ int VCHPOST_ vc_hostfs_chkdsk(const char *path, int fix_errors);
229
230/*---------------------------------------------------------------------------*/
231/* These functions only need to be implemented for the test system. */
232/*---------------------------------------------------------------------------*/
233
234// Open a log file.
235VCHPRE_ void VCHPOST_ vc_log_open(const char *fname);
236
237// Flush any pending data to the log file.
238VCHPRE_ void VCHPOST_ vc_log_flush(void);
239
240// Close the log file.
241VCHPRE_ void VCHPOST_ vc_log_close(void);
242
243// Log an error.
244VCHPRE_ void VCHPOST_ vc_log_error(const char *format, ...);
245
246// Log a warning.
247VCHPRE_ void VCHPOST_ vc_log_warning(const char *format, ...);
248
249// Write a message to the log.
250VCHPRE_ void VCHPOST_ vc_log_msg(const char *format, ...);
251
252// Flush the log.
253VCHPRE_ void VCHPOST_ vc_log_flush(void);
254
255// Return the total number of warnings and errors logged.
256VCHPRE_ void VCHPOST_ vc_log_counts(int *warnings, int *errors);
257
258// Wait for the specified number of microseconds. Used in test system only.
259VCHPRE_ void VCHPOST_ vc_sleep(int ms);
260
261// Get a time value in milliseconds. Used for measuring time differences
262VCHPRE_ uint32_t VCHPOST_ vc_time(void);
263
264// Check timing functions are available. Use in calibrating tests.
265VCHPRE_ int VCHPOST_ calibrate_sleep (const char *data_dir);
266
267/*---------------------------------------------------------------------------*/
268/* Functions to allow dynamic service creation */
269/*---------------------------------------------------------------------------*/
270
271VCHPRE_ void VCHPOST_ vc_host_get_vchi_state(VCHI_INSTANCE_T *initialise_instance, VCHI_CONNECTION_T **connection);
272
273#endif
274