/*
** Copyright (C) 2016 Airbus Group, stephane duverger <stephane.duverger@airbus.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along
** with this program; if not, write to the Free Software Foundation, Inc.,
** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __CTRL_EVT_H__
#define __CTRL_EVT_H__

#include <types.h>
#include <vm.h>

typedef int (*ctrl_evt_hdl_t)(arg_t);

/*
** VMM events are pre-hooks
*/
#define CTRL_EVT_VMM_TYPE_EXCP     0
#define CTRL_EVT_VMM_TYPE_HYP      1
#define CTRL_EVT_VMM_TYPE_NPF      2
#define CTRL_EVT_VMM_TYPE_WCR      3
#define CTRL_EVT_VMM_TYPE_S3       4
#define CTRL_EVT_VMM_TYPE_SMEM     5

/*
** User events are post-hooks
*/
#define CTRL_EVT_USR_TYPE_CR_RD    0
#define CTRL_EVT_USR_TYPE_CR_WR    1
#define CTRL_EVT_USR_TYPE_EXCP     2
#define CTRL_EVT_USR_TYPE_BRK      3
#define CTRL_EVT_USR_TYPE_SSTEP    4
#define CTRL_EVT_USR_TYPE_NPF      5
#define CTRL_EVT_USR_TYPE_HYP      6
#define CTRL_EVT_USR_TYPE_CPUID    7
#define CTRL_EVT_USR_TYPE_S3       8

typedef struct controller_event
{
   uint8_t         type;
   arg_t           arg;
   ctrl_evt_hdl_t  hdl;

} __attribute__((packed)) ctrl_evt_t;

/*
** Functions
*/
int  ctrl_evt_excp(uint32_t);
int  ctrl_evt_cr_rd(uint8_t);
int  ctrl_evt_cr_wr(uint8_t);
int  ctrl_evt_npf();
int  ctrl_evt_hypercall();
int  ctrl_evt_cpuid(uint32_t);
int  ctrl_evt_suspend();
int  ctrl_evt_sysmem(vm_access_t*);

int  ctrl_evt_setup(uint8_t, ctrl_evt_hdl_t, arg_t);
int  ctrl_event();

#endif
