/*
 * Copyright (c) 2005-2006 MIPS Technologies, Inc.
 * 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above
 *      copyright
 *        notice, this list of conditions and the following disclaimer
 *        in the documentation and/or other materials provided with
 *        the distribution.
 *      * Neither the name of MIPS Technologies Inc. nor the names of its
 *        contributors may be used to endorse or promote products derived
 *        from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * rtlx.h : MIPS MT Linux AP/SP communication 
 */

#ifndef _RTLX_H
#define _RTLX_H_

#define LX_NODE_BASE		10

#define MIPSCPU_INT_BASE	16
#define MIPS_CPU_RTLX_IRQ 	0

#define RTLX_VERSION 		2
#define RTLX_xID		0x12345600
#define RTLX_ID 		(RTLX_xID | RTLX_VERSION)
#define RTLX_CHANNELS 		8

enum rtlx_state {
	RTLX_STATE_UNUSED = 0,
	RTLX_STATE_INITIALISED,
	RTLX_STATE_REMOTE_READY,
	RTLX_STATE_OPENED
};

#define RTLX_BUFFER_SIZE	2048
#define RTLX_BUFFERS_PER_CHANNEL 2

/* Each channel supports read and write.  linux (vpe0) reads lx_buffer
   and writes rt_buffer SP (vpe1) reads rt_buffer and writes lx_buffer */

typedef struct rtlx_channel {
    enum rtlx_state		rt_state;
    enum rtlx_state		lx_state;
    
    unsigned int		buffer_size;

    /* read and write indexes per buffer */
    volatile unsigned int	rt_write, rt_read;
    volatile char *		rt_buffer;

    volatile unsigned int	lx_write, lx_read;
    volatile char *		lx_buffer;

} rtlx_channel_t;

typedef struct rtlx_info {
    unsigned long 	id;
    enum rtlx_state	state;
    struct rtlx_channel	channel[RTLX_CHANNELS];
} rtlx_info_t;

/* SDE public functions */
void _rtlx_init_early (void);
void _rtlx_init (void);
void _rtlx_set_shared (void *);
void _rtlx_interrupt_vpe (int);
int _rtlx_read_1char (void *, int, long);
int _rtlx_write_1char (void *, char, long);
int _rtlx_read_stdin (void *, int);
int _rtlx_write_stdout (const void *, int);
int _rtlx_open_dbg (void);
int _rtlx_close_dbg (void);
int _rtlx_read_dbg (void *, int);
int _rtlx_write_dbg (const void *, int);
int _rtlx_read_sys (void *, int);
int _rtlx_write_sys (const void *, int);
void _rtlx_state(void);

#endif /* _RTLX_H */
