xref: /illumos-gate/usr/src/uts/common/sys/sbp2/bus.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_SYS_SBP2_BUS_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_SBP2_BUS_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * Serial Bus Protocol 2 (SBP-2) bus interface
32*7c478bd9Sstevel@tonic-gate  */
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include <sys/sbp2/common.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/note.h>
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
38*7c478bd9Sstevel@tonic-gate extern "C" {
39*7c478bd9Sstevel@tonic-gate #endif
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate enum {
42*7c478bd9Sstevel@tonic-gate 	SBP2_BUS_REV_1	= 1,
43*7c478bd9Sstevel@tonic-gate 	SBP2_BUS_REV	= SBP2_BUS_REV_1
44*7c478bd9Sstevel@tonic-gate };
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate typedef struct sbp2_bus_buf {
47*7c478bd9Sstevel@tonic-gate 	struct sbp2_bus_buf *bb_next;	/* next in free list */
48*7c478bd9Sstevel@tonic-gate 	void		*bb_hdl;	/* buffer handle */
49*7c478bd9Sstevel@tonic-gate 	void		*bb_sbp2_priv;	/* SBP2 private data */
50*7c478bd9Sstevel@tonic-gate 	size_t		bb_len;		/* buffer length */
51*7c478bd9Sstevel@tonic-gate 	int		bb_flags;	/* flags */
52*7c478bd9Sstevel@tonic-gate 	int		bb_dma_flags;	/* DDI_DMA_* flags */
53*7c478bd9Sstevel@tonic-gate 	caddr_t		bb_kaddr;	/* kernel virtual address */
54*7c478bd9Sstevel@tonic-gate 	uint64_t	bb_paddr;	/* physical address */
55*7c478bd9Sstevel@tonic-gate 	uint64_t	bb_baddr;	/* bus address */
56*7c478bd9Sstevel@tonic-gate 	void		(*bb_rq_cb)(struct sbp2_bus_buf *bb, void *reqh,
57*7c478bd9Sstevel@tonic-gate 			    uint32_t *q);	/* quadlet read callback */
58*7c478bd9Sstevel@tonic-gate 	void		(*bb_rb_cb)(struct sbp2_bus_buf *bb, void *reqh,
59*7c478bd9Sstevel@tonic-gate 			    mblk_t **bpp, size_t len); /* block read callback */
60*7c478bd9Sstevel@tonic-gate 	void		(*bb_wq_cb)(struct sbp2_bus_buf *bb, void *reqh,
61*7c478bd9Sstevel@tonic-gate 			    uint32_t q);	/* quadlet write callback */
62*7c478bd9Sstevel@tonic-gate 	void		(*bb_wb_cb)(struct sbp2_bus_buf *bb, void *reqh,
63*7c478bd9Sstevel@tonic-gate 			    mblk_t **bpp);	/* block write callback */
64*7c478bd9Sstevel@tonic-gate } sbp2_bus_buf_t;
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", sbp2_bus_buf))
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate /* buffer flags */
69*7c478bd9Sstevel@tonic-gate enum {
70*7c478bd9Sstevel@tonic-gate 	SBP2_BUS_BUF_DMA	= 0x01,	/* DMA buffer */
71*7c478bd9Sstevel@tonic-gate 	SBP2_BUS_BUF_RD		= 0x02,	/* read buffer */
72*7c478bd9Sstevel@tonic-gate 	SBP2_BUS_BUF_WR		= 0x04,	/* write buffer */
73*7c478bd9Sstevel@tonic-gate 	SBP2_BUS_BUF_POSTED	= 0x08,	/* posted buffer */
74*7c478bd9Sstevel@tonic-gate 	SBP2_BUS_BUF_RW		= (SBP2_BUS_BUF_RD | SBP2_BUS_BUF_WR),
75*7c478bd9Sstevel@tonic-gate 	SBP2_BUS_BUF_WR_POSTED	= (SBP2_BUS_BUF_WR | SBP2_BUS_BUF_POSTED)
76*7c478bd9Sstevel@tonic-gate };
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate /* buffer request error codes */
79*7c478bd9Sstevel@tonic-gate enum {
80*7c478bd9Sstevel@tonic-gate 	SBP2_BUS_BUF_SUCCESS		= 0,
81*7c478bd9Sstevel@tonic-gate 	SBP2_BUS_BUF_FAILURE		= -1,	/* unspecified error */
82*7c478bd9Sstevel@tonic-gate 	SBP2_BUS_BUF_ELENGTH		= 1,	/* wrong data length */
83*7c478bd9Sstevel@tonic-gate 	SBP2_BUS_BUF_EBUSY		= 2	/* device busy */
84*7c478bd9Sstevel@tonic-gate };
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate typedef struct sbp2_bus {
87*7c478bd9Sstevel@tonic-gate 	int		sb_rev;
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 	/* static parameters */
90*7c478bd9Sstevel@tonic-gate 	uint64_t	sb_csr_base;	/* CSR base address */
91*7c478bd9Sstevel@tonic-gate 	uint64_t	sb_cfgrom_addr;	/* Config ROM address */
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate 	/* functions */
94*7c478bd9Sstevel@tonic-gate 	ddi_iblock_cookie_t (*sb_get_iblock_cookie)(void *hdl);
95*7c478bd9Sstevel@tonic-gate 	uint_t		(*sb_get_node_id)(void *hdl);
96*7c478bd9Sstevel@tonic-gate 	int		(*sb_alloc_buf)(void *hdl, sbp2_bus_buf_t *buf);
97*7c478bd9Sstevel@tonic-gate 	void		(*sb_free_buf)(void *hdl, sbp2_bus_buf_t *buf);
98*7c478bd9Sstevel@tonic-gate 	int		(*sb_sync_buf)(void *hdl, sbp2_bus_buf_t *buf,
99*7c478bd9Sstevel@tonic-gate 			    off_t offset, size_t length, int type);
100*7c478bd9Sstevel@tonic-gate 	void		(*sb_buf_rd_done)(void *hdl, sbp2_bus_buf_t *buf,
101*7c478bd9Sstevel@tonic-gate 			    void *reqh, int error);
102*7c478bd9Sstevel@tonic-gate 	void		(*sb_buf_wr_done)(void *hdl, sbp2_bus_buf_t *buf,
103*7c478bd9Sstevel@tonic-gate 			    void *reqh, int error);
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate 	int		(*sb_alloc_cmd)(void *hdl, void **cmdp, int flags);
106*7c478bd9Sstevel@tonic-gate 	void		(*sb_free_cmd)(void *hdl, void *cmd);
107*7c478bd9Sstevel@tonic-gate 	int		(*sb_rq)(void *hdl, void *cmd, uint64_t addr,
108*7c478bd9Sstevel@tonic-gate 			    uint32_t *q, int *berr);
109*7c478bd9Sstevel@tonic-gate 	int		(*sb_rb)(void *hdl, void *cmd, uint64_t addr,
110*7c478bd9Sstevel@tonic-gate 			    mblk_t **bpp, int len, int *err);
111*7c478bd9Sstevel@tonic-gate 	int		(*sb_wq)(void *hdl, void *cmd, uint64_t addr,
112*7c478bd9Sstevel@tonic-gate 			    uint32_t q, int *berr);
113*7c478bd9Sstevel@tonic-gate 	int		(*sb_wb)(void *hdl, void *cmd, uint64_t addr,
114*7c478bd9Sstevel@tonic-gate 			    mblk_t *bp, int len, int *berr);
115*7c478bd9Sstevel@tonic-gate } sbp2_bus_t;
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
118*7c478bd9Sstevel@tonic-gate }
119*7c478bd9Sstevel@tonic-gate #endif
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_SBP2_BUS_H */
122