#ifndef _LOG_H_
#define _LOG_H_
#include <stdint.h>

#define	LOG_MAGIC	(0xaabbccdd)

typedef struct log_info_s {
	/* This design is in accordance with mobicore requirements.
	 * Each log will obviously have a fixed (start_addr, size) spec.
	 * Also, since we can only map a small amount of data in driver at
	 * a time, we map only the header of the log and the page which has
	 * the tail of the log. These are the last two parameters.
	 */
	uint32_t log_start_paddr;
	uint32_t log_size;
	uint32_t log_hdr_vaddr;
	uint32_t log_data_vaddr;
} __attribute__ ((packed)) log_info_t;

#define	LOG_ENTRY_SIZE	128
typedef struct log_entry_s {
	uint32_t timestamp;	/* timestamp at which log entry was made */
	uint32_t logger_id;	/* id is 1 for tima, 2 for lkmauth app  */
#define	LOG_MSG_SIZE	(LOG_ENTRY_SIZE - sizeof(uint32_t) - sizeof(uint32_t))
	char log_msg[LOG_MSG_SIZE];	/* buffer for the entry                 */
} __attribute__ ((packed)) log_entry_t;

/* Size of header should be a multiple of LOG_ENTRY_SIZE */
typedef struct log_header_s {
	uint32_t magic;		/* magic number                         */
	uint32_t log_start_addr;	/* address at which log starts          */
	uint32_t log_write_addr;	/* address at which next entry is written */
	uint32_t num_log_entries;	/* number of log entries                */
	char padding[LOG_ENTRY_SIZE - 4 * sizeof(uint32_t)];
} __attribute__ ((packed)) log_header_t;

extern char g_log_msg[LOG_MSG_SIZE];

int32_t log_init(
	log_info_t
);
void log_msg(
	log_info_t,
	char *msg
);
int32_t log_read(
	int32_t region,
	int32_t entry_index,
	void *rsp
);
long inline get_time(
	void
);
#endif
