1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #ifndef _SYS_1394_TARGETS_DCAM1394_DCAM_H
28 #define _SYS_1394_TARGETS_DCAM1394_DCAM_H
29
30 #pragma ident "%Z%%M% %I% %E% SMI"
31
32 #include <sys/modctl.h>
33 #include <sys/ksynch.h>
34 #include <sys/types.h>
35 #include <sys/dditypes.h>
36 #include <sys/1394/t1394.h>
37 #include <sys/dcam/dcam1394_io.h>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 #define ILP32_PTR_SIZE 4 /* caller's data model type */
44 #define LP64_PTR_SIZE 8
45
46 #define DCAM_POWER_OFF 0 /* power management state */
47 #define DCAM_POWER_ON 1
48
49 #define DCAM1394_MINOR_CTRL 0x80 /* this is the control device */
50
51 #define DCAM1394_FLAG_ATTACH_COMPLETE 0x1 /* dcam_attach() is complete */
52 #define DCAM1394_FLAG_OPEN 0x2 /* driver is open */
53 #define DCAM1394_FLAG_OPEN_CAPTURE 0x4 /* device is open for capture */
54 #define DCAM1394_FLAG_OPEN_CONTROL 0x8 /* device is open for control */
55 #define DCAM1394_FLAG_FRAME_RCV_INIT 0x10
56 #define DCAM1394_FLAG_FRAME_RCVING 0x20
57 #define DCAM1394_FLAG_READ_REQ_PROC 0x40
58 #define DCAM1394_FLAG_READ_REQ_INVALID 0x80
59
60 #define IS_VALID 0x1
61 #define IS_PRESENT 0x2
62 #define CAP_GET 0x4
63 #define CAP_SET 0x8
64 #define CAP_CTRL_SET 0x10
65
66 #define MAX_STR_LEN 50
67
68 #define DEV_TO_INSTANCE(d) (getminor(d) & 0x7f)
69
70 typedef uint_t
71 dcam1394_param_attr_t[DCAM1394_NUM_PARAM][DCAM1394_NUM_SUBPARAM];
72
73 typedef struct buff_info_s {
74 uint_t vid_mode;
75 unsigned int seq_num;
76 hrtime_t timestamp;
77 caddr_t kaddr_p; /* kernel data buffer */
78 ddi_dma_handle_t dma_handle; /* bind handle */
79 ddi_acc_handle_t data_acc_handle; /* acc handle */
80 ddi_dma_cookie_t dma_cookie; /* cookie */
81 size_t real_len; /* mem len */
82 uint_t dma_cookie_count; /* cookie count */
83 } buff_info_t;
84
85 #define MAX_NUM_READ_PTRS 1
86
87 typedef struct ring_buff_s {
88 size_t num_buffs;
89 size_t buff_num_bytes;
90 buff_info_t *buff_info_array_p;
91 int num_read_ptrs;
92 int read_ptr_incr_val;
93 size_t read_ptr_pos[MAX_NUM_READ_PTRS];
94 uint_t status[MAX_NUM_READ_PTRS];
95 size_t write_ptr_pos;
96 } ring_buff_t;
97
98 typedef struct dcam_state_s {
99 dev_info_t *dip;
100 int instance;
101 int usr_model;
102 t1394_handle_t sl_handle;
103 t1394_attachinfo_t attachinfo;
104 t1394_targetinfo_t targetinfo;
105 t1394_isoch_singleinfo_t sii;
106 t1394_isoch_single_out_t sii_output_args;
107 t1394_isoch_single_handle_t sii_hdl;
108 t1394_isoch_dma_handle_t isoch_handle;
109 kmutex_t softc_mutex;
110 kmutex_t dcam_frame_is_done_mutex;
111 dcam1394_param_attr_t param_attr;
112
113 ixl1394_command_t *ixlp;
114
115 ring_buff_t *ring_buff_p;
116 unsigned int seq_count;
117 uint_t reader_flags[MAX_NUM_READ_PTRS];
118 uint_t flags;
119 int cur_vid_mode;
120 int cur_frame_rate;
121 int cur_ring_buff_capacity;
122 int param_status;
123 struct pollhead dcam_pollhead;
124 int camera_online;
125 int pm_open_count;
126 int pm_cable_power;
127 int suspended;
128 ddi_callback_id_t event_id;
129 } dcam_state_t;
130
131 int _init(void);
132 int _info(struct modinfo *modinfop);
133 int _fini(void);
134
135 int dcam_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
136 int dcam_power(dev_info_t *dip, int component, int level);
137 int dcam_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result);
138 int dcam_identify(dev_info_t *dip);
139 int dcam_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
140 int dcam_open(dev_t *devp, int flag, int otyp, cred_t *credp);
141 int dcam_close(dev_t dev, int flags, int otyp, cred_t *credp);
142 int dcam_read(dev_t dev, struct uio *uio, cred_t *credp);
143 int dcam_write(dev_t dev, struct uio *uio, cred_t *credp);
144 int dcam_mmap(dev_t dev, off_t off, int prot);
145 int dcam_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off, size_t len,
146 size_t *maplen, uint_t model);
147 int dcam_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
148 cred_t *credp, int *rvalp);
149 int dcam_chpoll(dev_t dev, short events, int anyyet, short *reventsp,
150 struct pollhead **phpp);
151 int dcam_intr(caddr_t dcam_softc_p);
152 void dcam_bus_reset_notify(dev_info_t *dip, ddi_eventcookie_t ev_cookie,
153 void *arg, void *impl_data);
154
155
156 ring_buff_t *ring_buff_create(dcam_state_t *softc_p, size_t num_buffs,
157 size_t buff_num_bytes);
158 void ring_buff_free(dcam_state_t *softc_p, ring_buff_t *ring_buff_p);
159 int ring_buff_reader_add(ring_buff_t *ring_buff_p);
160 int ring_buff_reader_remove(ring_buff_t *ring_buff_p, int reader_id);
161 buff_info_t *ring_buff_read_ptr_buff_get(ring_buff_t *ring_buff_p, int
162 reader_id);
163 size_t ring_buff_read_ptr_pos_get(ring_buff_t *ring_buff_p, int read_ptr_id);
164 void ring_buff_read_ptr_incr(ring_buff_t *ring_buff_p, int read_ptr_id);
165 size_t ring_buff_write_ptr_pos_get(ring_buff_t *ring_buff_p);
166 void ring_buff_write_ptr_incr(ring_buff_t *ring_buff_p);
167 int dcam_frame_rcv_stop(dcam_state_t *softc_p);
168 int dcam1394_ioctl_frame_rcv_start(dcam_state_t *softc_p);
169
170 #ifdef __cplusplus
171 }
172 #endif
173
174 #endif /* _SYS_1394_TARGETS_DCAM1394_DCAM_H */