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 * Copyright 2017 Joyent, Inc. 26 */ 27 28 #ifndef _SYS_1394_TARGETS_DCAM1394_DCAM_H 29 #define _SYS_1394_TARGETS_DCAM1394_DCAM_H 30 31 #include <sys/modctl.h> 32 #include <sys/ksynch.h> 33 #include <sys/types.h> 34 #include <sys/dditypes.h> 35 #include <sys/1394/t1394.h> 36 #include <sys/dcam/dcam1394_io.h> 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 #define ILP32_PTR_SIZE 4 /* caller's data model type */ 43 #define LP64_PTR_SIZE 8 44 45 #define DCAM_POWER_OFF 0 /* power management state */ 46 #define DCAM_POWER_ON 1 47 48 #define DCAM1394_MINOR_CTRL 0x80 /* this is the control device */ 49 50 #define DCAM1394_FLAG_ATTACH_COMPLETE 0x1 /* dcam_attach() is complete */ 51 #define DCAM1394_FLAG_OPEN 0x2 /* driver is open */ 52 #define DCAM1394_FLAG_OPEN_CAPTURE 0x4 /* device is open for capture */ 53 #define DCAM1394_FLAG_OPEN_CONTROL 0x8 /* device is open for control */ 54 #define DCAM1394_FLAG_FRAME_RCV_INIT 0x10 55 #define DCAM1394_FLAG_FRAME_RCVING 0x20 56 #define DCAM1394_FLAG_READ_REQ_PROC 0x40 57 #define DCAM1394_FLAG_READ_REQ_INVALID 0x80 58 59 #define IS_VALID 0x1 60 #define IS_PRESENT 0x2 61 #define CAP_GET 0x4 62 #define CAP_SET 0x8 63 #define CAP_CTRL_SET 0x10 64 65 #define MAX_STR_LEN 50 66 67 #define DEV_TO_INSTANCE(d) (getminor(d) & 0x7f) 68 69 typedef uint_t 70 dcam1394_param_attr_t[DCAM1394_NUM_PARAM][DCAM1394_NUM_SUBPARAM]; 71 72 typedef struct buff_info_s { 73 uint_t vid_mode; 74 unsigned int seq_num; 75 hrtime_t timestamp; 76 caddr_t kaddr_p; /* kernel data buffer */ 77 ddi_dma_handle_t dma_handle; /* bind handle */ 78 ddi_acc_handle_t data_acc_handle; /* acc handle */ 79 ddi_dma_cookie_t dma_cookie; /* cookie */ 80 size_t real_len; /* mem len */ 81 uint_t dma_cookie_count; /* cookie count */ 82 } buff_info_t; 83 84 #define MAX_NUM_READ_PTRS 1 85 86 typedef struct ring_buff_s { 87 size_t num_buffs; 88 size_t buff_num_bytes; 89 buff_info_t *buff_info_array_p; 90 int num_read_ptrs; 91 int read_ptr_incr_val; 92 size_t read_ptr_pos[MAX_NUM_READ_PTRS]; 93 uint_t status[MAX_NUM_READ_PTRS]; 94 size_t write_ptr_pos; 95 } ring_buff_t; 96 97 typedef struct dcam_state_s { 98 dev_info_t *dip; 99 int instance; 100 int usr_model; 101 t1394_handle_t sl_handle; 102 t1394_attachinfo_t attachinfo; 103 t1394_targetinfo_t targetinfo; 104 t1394_isoch_singleinfo_t sii; 105 t1394_isoch_single_out_t sii_output_args; 106 t1394_isoch_single_handle_t sii_hdl; 107 t1394_isoch_dma_handle_t isoch_handle; 108 kmutex_t softc_mutex; 109 kmutex_t dcam_frame_is_done_mutex; 110 dcam1394_param_attr_t param_attr; 111 112 ixl1394_command_t *ixlp; 113 114 ring_buff_t *ring_buff_p; 115 unsigned int seq_count; 116 uint_t reader_flags[MAX_NUM_READ_PTRS]; 117 uint_t flags; 118 int cur_vid_mode; 119 int cur_frame_rate; 120 int cur_ring_buff_capacity; 121 int param_status; 122 int camera_online; 123 int pm_open_count; 124 int pm_cable_power; 125 int suspended; 126 ddi_callback_id_t event_id; 127 } dcam_state_t; 128 129 int _init(void); 130 int _info(struct modinfo *modinfop); 131 int _fini(void); 132 133 int dcam_attach(dev_info_t *dip, ddi_attach_cmd_t cmd); 134 int dcam_power(dev_info_t *dip, int component, int level); 135 int dcam_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result); 136 int dcam_identify(dev_info_t *dip); 137 int dcam_detach(dev_info_t *dip, ddi_detach_cmd_t cmd); 138 int dcam_open(dev_t *devp, int flag, int otyp, cred_t *credp); 139 int dcam_close(dev_t dev, int flags, int otyp, cred_t *credp); 140 int dcam_read(dev_t dev, struct uio *uio, cred_t *credp); 141 int dcam_write(dev_t dev, struct uio *uio, cred_t *credp); 142 int dcam_mmap(dev_t dev, off_t off, int prot); 143 int dcam_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off, size_t len, 144 size_t *maplen, uint_t model); 145 int dcam_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, 146 cred_t *credp, int *rvalp); 147 int dcam_chpoll(dev_t dev, short events, int anyyet, short *reventsp, 148 struct pollhead **phpp); 149 int dcam_intr(caddr_t dcam_softc_p); 150 void dcam_bus_reset_notify(dev_info_t *dip, ddi_eventcookie_t ev_cookie, 151 void *arg, void *impl_data); 152 153 154 ring_buff_t *ring_buff_create(dcam_state_t *softc_p, size_t num_buffs, 155 size_t buff_num_bytes); 156 void ring_buff_free(dcam_state_t *softc_p, ring_buff_t *ring_buff_p); 157 int ring_buff_reader_add(ring_buff_t *ring_buff_p); 158 int ring_buff_reader_remove(ring_buff_t *ring_buff_p, int reader_id); 159 buff_info_t *ring_buff_read_ptr_buff_get(ring_buff_t *ring_buff_p, int 160 reader_id); 161 size_t ring_buff_read_ptr_pos_get(ring_buff_t *ring_buff_p, int read_ptr_id); 162 void ring_buff_read_ptr_incr(ring_buff_t *ring_buff_p, int read_ptr_id); 163 size_t ring_buff_write_ptr_pos_get(ring_buff_t *ring_buff_p); 164 void ring_buff_write_ptr_incr(ring_buff_t *ring_buff_p); 165 int dcam_frame_rcv_stop(dcam_state_t *softc_p); 166 int dcam1394_ioctl_frame_rcv_start(dcam_state_t *softc_p); 167 168 #ifdef __cplusplus 169 } 170 #endif 171 172 #endif /* _SYS_1394_TARGETS_DCAM1394_DCAM_H */ 173