1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  Device manager definitions		File: cfe_device.h
5    *
6    *  Structures, constants, etc. for the device manager, which keeps
7    *  track of installed devices in CFE.
8    *
9    *  Author:  Mitch Lichtenberg
10    *
11    *********************************************************************
12    *
13    *  Copyright 2000,2001,2002,2003
14    *  Broadcom Corporation. All rights reserved.
15    *
16    *  This software is furnished under license and may be used and
17    *  copied only in accordance with the following terms and
18    *  conditions.  Subject to these conditions, you may download,
19    *  copy, install, use, modify and distribute modified or unmodified
20    *  copies of this software in source and/or binary form.  No title
21    *  or ownership is transferred hereby.
22    *
23    *  1) Any source code used, modified or distributed must reproduce
24    *     and retain this copyright notice and list of conditions
25    *     as they appear in the source file.
26    *
27    *  2) No right is granted to use any trade name, trademark, or
28    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
29    *     name may not be used to endorse or promote products derived
30    *     from this software without the prior written permission of
31    *     Broadcom Corporation.
32    *
33    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
34    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
35    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
37    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
38    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
39    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
43    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
44    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
45    *     THE POSSIBILITY OF SUCH DAMAGE.
46    ********************************************************************* */
47
48
49#ifndef _CFE_DEVICE_H
50#define _CFE_DEVICE_H
51
52#include "lib_queue.h"
53
54typedef struct cfe_devdisp_s cfe_devdisp_t;
55
56
57/*
58 * The Device structure defines a particular instance of a device.
59 * They are generated as a result of calling the cfe_attach call.
60 */
61
62typedef struct cfe_device_s {
63    queue_t dev_next;
64    char *dev_fullname;
65    void *dev_softc;
66    int dev_class;
67    const cfe_devdisp_t *dev_dispatch;
68    int dev_opencount;
69    char *dev_description;
70} cfe_device_t;
71
72/*
73 * This is what gets returned from the OPEN call
74 */
75typedef struct cfe_devctx_s {
76    cfe_device_t *dev_dev;
77    void *dev_softc;
78    void *dev_openinfo;
79} cfe_devctx_t;
80
81
82/*
83 * This defines a given device class.  Even though there are
84 * three identical MACs, there is only one of these.
85 */
86
87struct cfe_devdisp_s {
88    int (*dev_open)(cfe_devctx_t *ctx);
89    int (*dev_read)(cfe_devctx_t *ctx,iocb_buffer_t *buffer);
90    int (*dev_inpstat)(cfe_devctx_t *ctx,iocb_inpstat_t *inpstat);
91    int (*dev_write)(cfe_devctx_t *ctx,iocb_buffer_t *buffer);
92    int (*dev_ioctl)(cfe_devctx_t *ctx,iocb_buffer_t *buffer);
93    int (*dev_close)(cfe_devctx_t *ctx);
94    void (*dev_poll)(cfe_devctx_t *ctx,int64_t ticks);
95    void (*dev_reset)(void *softc);	/* called when device is closed, so no devctx_t */
96};
97
98
99
100typedef struct cfe_driver_s {
101    char *drv_description;		/* Description of device for SHOW commands */
102    char *drv_bootname;			/* Device's name prefix for open() */
103    int drv_class;
104    const cfe_devdisp_t *drv_dispatch;
105    void (*drv_probe)(struct cfe_driver_s *drv,
106		      unsigned long probe_a, unsigned long probe_b,
107		      void *probe_ptr);
108} cfe_driver_t;
109
110char *cfe_device_name(cfe_devctx_t *ctx);
111void cfe_attach(cfe_driver_t *devname,void *softc,char *bootinfo,char *description);
112int cfe_attach_idx(cfe_driver_t *drv,int idx,void *softc,char *bootinfo,char *description);
113cfe_device_t *cfe_finddev(char *name);
114int cfe_dev_enum(int idx,char *name,int *namelen);
115void cfe_attach_init(void);
116#define cfe_add_device(devdescr,a,b,ptr) (devdescr)->drv_probe(devdescr,a,b,ptr)
117void cfe_device_reset(void);
118
119#endif
120