162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * I/O Processor (IOP) defines and structures, mostly snagged from A/UX
462306a36Sopenharmony_ci * header files.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * The original header from which this was taken is copyrighted. I've done some
762306a36Sopenharmony_ci * rewriting (in fact my changes make this a bit more readable, IMHO) but some
862306a36Sopenharmony_ci * more should be done.
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci/*
1262306a36Sopenharmony_ci * This is the base address of the IOPs. Use this as the address of
1362306a36Sopenharmony_ci * a "struct iop" (see below) to see where the actual registers fall.
1462306a36Sopenharmony_ci */
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define SCC_IOP_BASE_IIFX	(0x50F04000)
1762306a36Sopenharmony_ci#define ISM_IOP_BASE_IIFX	(0x50F12000)
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#define SCC_IOP_BASE_QUADRA	(0x50F0C000)
2062306a36Sopenharmony_ci#define ISM_IOP_BASE_QUADRA	(0x50F1E000)
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/* IOP status/control register bits: */
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define	IOP_BYPASS	0x01	/* bypass-mode hardware access */
2562306a36Sopenharmony_ci#define	IOP_AUTOINC	0x02	/* allow autoincrement of ramhi/lo */
2662306a36Sopenharmony_ci#define	IOP_RUN		0x04	/* set to 0 to reset IOP chip */
2762306a36Sopenharmony_ci#define	IOP_IRQ		0x08	/* generate IRQ to IOP if 1 */
2862306a36Sopenharmony_ci#define	IOP_INT0	0x10	/* intr priority from IOP to host */
2962306a36Sopenharmony_ci#define	IOP_INT1	0x20	/* intr priority from IOP to host */
3062306a36Sopenharmony_ci#define	IOP_HWINT	0x40	/* IRQ from hardware; bypass mode only */
3162306a36Sopenharmony_ci#define	IOP_DMAINACTIVE	0x80	/* no DMA request active; bypass mode only */
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#define NUM_IOPS	2
3462306a36Sopenharmony_ci#define NUM_IOP_CHAN	7
3562306a36Sopenharmony_ci#define NUM_IOP_MSGS	NUM_IOP_CHAN*8
3662306a36Sopenharmony_ci#define IOP_MSG_LEN	32
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci/* IOP reference numbers, used by the globally-visible iop_xxx functions */
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci#define IOP_NUM_SCC	0
4162306a36Sopenharmony_ci#define IOP_NUM_ISM	1
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/* IOP channel states */
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#define IOP_MSG_IDLE		0       /* idle                         */
4662306a36Sopenharmony_ci#define IOP_MSG_NEW		1       /* new message sent             */
4762306a36Sopenharmony_ci#define IOP_MSG_RCVD		2       /* message received; processing */
4862306a36Sopenharmony_ci#define IOP_MSG_COMPLETE	3       /* message processing complete  */
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/* IOP message status codes */
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci#define IOP_MSGSTATUS_UNUSED	0	/* Unused message structure        */
5362306a36Sopenharmony_ci#define IOP_MSGSTATUS_WAITING	1	/* waiting for channel             */
5462306a36Sopenharmony_ci#define IOP_MSGSTATUS_SENT	2	/* message sent, awaiting reply    */
5562306a36Sopenharmony_ci#define IOP_MSGSTATUS_COMPLETE	3	/* message complete and reply rcvd */
5662306a36Sopenharmony_ci#define IOP_MSGSTATUS_UNSOL	6	/* message is unsolicited          */
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/* IOP memory addresses of the members of the mac_iop_kernel structure. */
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define IOP_ADDR_MAX_SEND_CHAN	0x0200
6162306a36Sopenharmony_ci#define IOP_ADDR_SEND_STATE	0x0201
6262306a36Sopenharmony_ci#define IOP_ADDR_PATCH_CTRL	0x021F
6362306a36Sopenharmony_ci#define IOP_ADDR_SEND_MSG	0x0220
6462306a36Sopenharmony_ci#define IOP_ADDR_MAX_RECV_CHAN	0x0300
6562306a36Sopenharmony_ci#define IOP_ADDR_RECV_STATE	0x0301
6662306a36Sopenharmony_ci#define IOP_ADDR_ALIVE		0x031F
6762306a36Sopenharmony_ci#define IOP_ADDR_RECV_MSG	0x0320
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci#ifndef __ASSEMBLY__
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci/*
7262306a36Sopenharmony_ci * IOP Control registers, staggered because in usual Apple style they were
7362306a36Sopenharmony_ci * too lazy to decode the A0 bit. This structure is assumed to begin at
7462306a36Sopenharmony_ci * one of the xxx_IOP_BASE addresses given above.
7562306a36Sopenharmony_ci */
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_cistruct mac_iop {
7862306a36Sopenharmony_ci    __u8	ram_addr_hi;	/* shared RAM address hi byte */
7962306a36Sopenharmony_ci    __u8	pad0;
8062306a36Sopenharmony_ci    __u8	ram_addr_lo;	/* shared RAM address lo byte */
8162306a36Sopenharmony_ci    __u8	pad1;
8262306a36Sopenharmony_ci    __u8	status_ctrl;	/* status/control register */
8362306a36Sopenharmony_ci    __u8	pad2[3];
8462306a36Sopenharmony_ci    __u8	ram_data;	/* RAM data byte at ramhi/lo */
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci    __u8	pad3[23];
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci    /* Bypass-mode hardware access registers */
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci    union {
9162306a36Sopenharmony_ci	struct {		/* SCC registers */
9262306a36Sopenharmony_ci	    __u8 sccb_cmd;	/* SCC B command reg */
9362306a36Sopenharmony_ci	    __u8 pad4;
9462306a36Sopenharmony_ci	    __u8 scca_cmd;	/* SCC A command reg */
9562306a36Sopenharmony_ci	    __u8 pad5;
9662306a36Sopenharmony_ci	    __u8 sccb_data;	/* SCC B data */
9762306a36Sopenharmony_ci	    __u8 pad6;
9862306a36Sopenharmony_ci	    __u8 scca_data;	/* SCC A data */
9962306a36Sopenharmony_ci	} scc_regs;
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci	struct {		/* ISM registers */
10262306a36Sopenharmony_ci	    __u8 wdata;		/* write a data byte */
10362306a36Sopenharmony_ci	    __u8 pad7;
10462306a36Sopenharmony_ci	    __u8 wmark;		/* write a mark byte */
10562306a36Sopenharmony_ci	    __u8 pad8;
10662306a36Sopenharmony_ci	    __u8 wcrc;		/* write 2-byte crc to disk */
10762306a36Sopenharmony_ci	    __u8 pad9;
10862306a36Sopenharmony_ci	    __u8 wparams;	/* write the param regs */
10962306a36Sopenharmony_ci	    __u8 pad10;
11062306a36Sopenharmony_ci	    __u8 wphase;	/* write the phase states & dirs */
11162306a36Sopenharmony_ci	    __u8 pad11;
11262306a36Sopenharmony_ci	    __u8 wsetup;	/* write the setup register */
11362306a36Sopenharmony_ci	    __u8 pad12;
11462306a36Sopenharmony_ci	    __u8 wzeroes;	/* mode reg: 1's clr bits, 0's are x */
11562306a36Sopenharmony_ci	    __u8 pad13;
11662306a36Sopenharmony_ci	    __u8 wones;		/* mode reg: 1's set bits, 0's are x */
11762306a36Sopenharmony_ci	    __u8 pad14;
11862306a36Sopenharmony_ci	    __u8 rdata;		/* read a data byte */
11962306a36Sopenharmony_ci	    __u8 pad15;
12062306a36Sopenharmony_ci	    __u8 rmark;		/* read a mark byte */
12162306a36Sopenharmony_ci	    __u8 pad16;
12262306a36Sopenharmony_ci	    __u8 rerror;	/* read the error register */
12362306a36Sopenharmony_ci	    __u8 pad17;
12462306a36Sopenharmony_ci	    __u8 rparams;	/* read the param regs */
12562306a36Sopenharmony_ci	    __u8 pad18;
12662306a36Sopenharmony_ci	    __u8 rphase;	/* read the phase states & dirs */
12762306a36Sopenharmony_ci	    __u8 pad19;
12862306a36Sopenharmony_ci	    __u8 rsetup;	/* read the setup register */
12962306a36Sopenharmony_ci	    __u8 pad20;
13062306a36Sopenharmony_ci	    __u8 rmode;		/* read the mode register */
13162306a36Sopenharmony_ci	    __u8 pad21;
13262306a36Sopenharmony_ci	    __u8 rhandshake;	/* read the handshake register */
13362306a36Sopenharmony_ci	} ism_regs;
13462306a36Sopenharmony_ci    } b;
13562306a36Sopenharmony_ci};
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci/* This structure is used to track IOP messages in the Linux kernel */
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_cistruct iop_msg {
14062306a36Sopenharmony_ci	struct iop_msg	*next;		/* next message in queue or NULL     */
14162306a36Sopenharmony_ci	uint	iop_num;		/* IOP number                        */
14262306a36Sopenharmony_ci	uint	channel;		/* channel number                    */
14362306a36Sopenharmony_ci	void	*caller_priv;		/* caller private data               */
14462306a36Sopenharmony_ci	int	status;			/* status of this message            */
14562306a36Sopenharmony_ci	__u8	message[IOP_MSG_LEN];	/* the message being sent/received   */
14662306a36Sopenharmony_ci	__u8	reply[IOP_MSG_LEN];	/* the reply to the message          */
14762306a36Sopenharmony_ci	void	(*handler)(struct iop_msg *);
14862306a36Sopenharmony_ci					/* function to call when reply recvd */
14962306a36Sopenharmony_ci};
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ciextern int iop_scc_present,iop_ism_present;
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ciextern int iop_listen(uint, uint,
15462306a36Sopenharmony_ci			void (*handler)(struct iop_msg *),
15562306a36Sopenharmony_ci			const char *);
15662306a36Sopenharmony_ciextern int iop_send_message(uint, uint, void *, uint, __u8 *,
15762306a36Sopenharmony_ci			    void (*)(struct iop_msg *));
15862306a36Sopenharmony_ciextern void iop_complete_message(struct iop_msg *);
15962306a36Sopenharmony_ciextern void iop_upload_code(uint, __u8 *, uint, __u16);
16062306a36Sopenharmony_ciextern void iop_download_code(uint, __u8 *, uint, __u16);
16162306a36Sopenharmony_ciextern __u8 *iop_compare_code(uint, __u8 *, uint, __u16);
16262306a36Sopenharmony_ciextern void iop_ism_irq_poll(uint);
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ciextern void iop_register_interrupts(void);
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci#endif /* __ASSEMBLY__ */
167