1 IEC61883(7I) Ioctl Requests IEC61883(7I) 2 3 NAME 4 iec61883 - IEC 61883 interfaces 5 6 SYNOPSIS 7 #include <sys/av/iec61883.h> 8 9 DESCRIPTION 10 The set of interfaces described in this man page can be used to control 11 and exchange data with consumer audio/video devices using protocols 12 specified in IIEC 61883 Consumer Electronic Audio/Video Equipment - 13 Digital Interface including Common Isochronous Packet (CIP), Connection 14 Management Procedures (CMP) and Function Control Protocol (FCP). 15 16 An iec61883 compliant driver exports two device nodes for isochronous and 17 for asynchronous transactions. See the FILES section of this man page 18 for the namespace definition. 19 20 Isochronous Transfers 21 Two methods are provided to receive/transmit isochronous data: using 22 mmap(2) in combination with ioctl(2), and read(2) or write(2). 23 24 Mmap/Ioctl 25 This method provides better performance and finer-grained control than 26 read/write, and is a method of choice for most applications. The data 27 buffer is mapped into a user process address space, which means no data 28 copying between the kernel and an application is necessary. 29 Synchronization between user processes and the driver is performed using 30 ioctl(2) commands. 31 32 An application allocates resources for isochronous transfer using 33 IEC61883_ISOCH_INIT. Then the data buffer can be mapped into the process 34 space using mmap(2). 35 36 A circular data buffer consists of one or more equal size frame buffers 37 (further referred to as frames, unless to avoid ambiguity with AV 38 frames). Frames are numbered starting with zero and are always 39 transferred sequentially. Frames consist equal sized packets. Each 40 packet contains a CIP header and one or more data blocks. 41 42 A driver and an application act as a producer and a consumer: producer 43 supplies full frames (filled with data) to the consumer, and the producer 44 is not allowed to access those frames until the consumer claims them 45 empty. 46 47 A transfer can be initiated and suspended with IEC61883_START and 48 IEC61883_STOP commands respectively. IEC61883_RECV or IEC61883_XMIT is 49 used for producer-consumer synchronization. 50 51 Read/Write 52 Using this method, an application calls read(2) or write(2) to receive or 53 transmit a specified amount of data. Bus-specific overhead, such as 54 isochronous packet headers, is handled by the driver and is not exposed 55 to applications. Data returned by read(2) contains CIP headers and data 56 blocks. Empty packets are not returned by read(2). write(2) data should 57 meet the same requirements. 58 59 If one or more channels have been allocated since open(2) (see 60 IEC61883_ISOCH_INIT), the data is received/transmitted using channel that 61 was created the last. 62 63 If no channels were allocated, the driver uses the broadcast channel by 64 default and allocates the default-size data buffer. During transmit, the 65 first packet's CIP header is used to auto-detect the data format. If it 66 is one of the formats supported by the driver, it is properly transmitted 67 (with inserted empty packets and timestamps). 68 69 For both methods, if during transmit the driver runs out of data, it 70 transmits empty packets containing only a CIP header of the next to be 71 transmitted packet, as defined in IEC 61883-1. 72 73 Connection Management Procedures 74 Applications wishing to follow Connection Management Procedures (CMP) in 75 combination with isochronous transfers should use the ioctl(2) 76 IEC61883_PLUG_INIT, IEC61883_PLUG_FINI, IEC61883_PLUG_REG_READ and 77 IEC61883_PLUG_REG_CAS commands. 78 79 Asynchronous Transactions 80 read(2), write(2), ioctl(2), and poll(2) can be used with asynchronous 81 nodes. Asynchronous data exchange between a driver and an application 82 utilizes a common data structure called asynchronous request (ARQ): 83 84 typedef struct iec61883_arq { 85 int arq_type; 86 int arq_len; 87 union { 88 uint32_t quadlet; 89 uint64_t octlet; 90 uint8_t buf[8]; 91 } arq_data; 92 } iec61883_arq_t; 93 94 arq_type contains ARQ type: 95 96 IEC61883_ARQ_FCP_CMD 97 IEC61883_ARQ_FCP_RESP 98 99 FCP command and response frame respectively. Outgoing frames are sent 100 using write(2), incoming frames are received with read(2). 101 102 See IIEC 61883-1 for the FCP frame structure definition. 103 104 IEC61883_ARQ_BUS_RESET 105 106 Returned by the driver when a bus reset occurs. There is no data 107 associated with this request type, and arq_len is set to 0. 108 109 If arq_len is 4 or 8, then data should be supplied in arq_data.quadlet or 110 arq_data.octlet respectively, otherwise up to 8 bytes can be put in 111 arq_data.buf, with the rest of the data following immediately after. 112 113 write(2) 114 For a request to be sent to a target, an iec61883_arq_t structure along 115 with associated data is passed to the driver using write(2). write(2) 116 blocks until the request is completed. 117 118 read(2) 119 A driver collects incoming ARQs in the internal buffer. Buffer size can 120 be changed using the ioctl(2) command IEC61883_FCP_SET_IBUF_SIZE. 121 122 Reading an ARQ takes one or two steps depending on data length. An 123 application first reads `sizeof (iec61883_arq_t)' bytes: if arq_len is 124 less than or equal 4, which is usually the case, no additional step is 125 needed. Otherwise, the remaining `arq_len - 4' bytes should be read and 126 concatenated. 127 128 read(2) blocks until the specified amount of data is available, unless 129 O_NONBLOCK or O_NDELAY flag was set during open(2), in which case read(2) 130 returns immediately. 131 132 poll(2) 133 Applications can poll(2) asynchronous nodes on the POLLIN event. 134 135 Bus Reset 136 In case of a bus reset, the driver notifies an application by generating 137 an ARQ of type IEC61883_ARQ_BUS_RESET. 138 139 If there were established isochronous connections before bus reset, the 140 driver attempts to restore all connections as described in IEC 61883 and 141 resume any active transfers that were in progress. 142 143 IOCTLS 144 The following commands only apply to isochronous nodes: 145 146 IEC61883_ISOCH_INIT 147 148 This command allocates a data buffer and isochronous resources (if 149 necessary) for the isochronous transfer. The argument is a pointer to 150 the structure: 151 152 typedef struct iec61883_isoch_init { 153 int ii_version; /* interface version */ 154 int ii_pkt_size; /* packet size */ 155 int ii_frame_size; /* packets/frame */ 156 int ii_frame_cnt; /* # of frames */ 157 int ii_direction; /* xfer direction */ 158 int ii_bus_speed; /* bus speed */ 159 uint64_t ii_channel; /* channel mask */ 160 int ii_dbs; /* DBS */ 161 int ii_fn; /* FN */ 162 int ii_rate_n; /* rate numerator */ 163 int ii_rate_d; /* rate denominator */ 164 int ii_ts_mode; /* timestamp mode */ 165 int ii_flags; /* flags */ 166 int ii_handle; /* isoch handle */ 167 int ii_frame_rcnt; /* # of frames */ 168 off_t *ii_mmap_off /* mmap offset */ 169 int ii_rchannel; /* channel */ 170 int ii_error; /* error code */ 171 } iec61883_isoch_init_t; 172 173 ii_version should be set to IEC61883_V1_0. 174 175 The driver attempts to allocate a data buffer consisting of 176 ii_frame_cnt frames, with ii_frame_size packets in each frame. Packet 177 size in bytes is specified by ii_pkt_size specifies and should be a 178 multiple of 512 and compatible with ii_bus_speed. 179 180 ii_direction can take one of the following values: 181 182 IEC61883_DIR_RECV Receiving isochronous data. 183 184 IEC61883_DIR_XMIT Transmitting isochronous data. 185 186 ii_bus_speed chooses bus speed to be used and can be either 187 IEC61883_S100, IEC61883_S200 or IEC61883_S400. 188 189 ii_channel is a mask that specifies an isochronous channel number to 190 be used, with the Nth bit representing channel N. When transmitting 191 data, several bits can be set at a time, in which case the driver 192 chooses one, for example, 0x3FF means a range from 0 to 9. In case of 193 receive, only one bit can be set. 194 195 ii_dbs specifies data block size in quadlets, for example, DBS value 196 for SD-DVCR is 0x78. Refer to IEC 61883 for more details on DBS. 197 198 ii_fn specifies fraction number, which defines the number of blocks in 199 which a source packet is divided. Allowed values are from 0 to 3. 200 Refer to IEC 61883 for more details on FN. 201 202 Data rate expected by the AV device can be lower than the bus speed, 203 in which case the driver has to periodically insert empty packets into 204 the data stream to avoid device buffer overflows. This rate is 205 specified with a fraction N/D, set by ii_rate_n and ii_rate_d 206 respectively. Any integer numbers can be used, or the following 207 predefined constants: 208 209 IEC61883_RATE_N_DV_NTSC 210 IEC61883_RATE_D_DV_NTSC Data rate expected by DV-NTSC devices. 211 212 IEC61883_RATE_N_DV_PAL 213 IEC61883_RATE_D_DV_PAL Data rate expected by DV-PAL devices. 214 215 During data transmission, a timestamp based on the current value of 216 the cycle timer is usually required. ii_ts_mode defines timestamp 217 mode to be used: 218 219 IEC61883_TS_SYT Driver puts a timestamp in the SYT field of the 220 first CIP header of each frame. 221 222 IEC61883_TS_NONE No timestamps. 223 224 ii_dbs, ii_fn, ii_rate_n, ii_rate_d and ii_ts_mode are only required 225 for transmission. In other case these should be set to 0. 226 227 ii_flags should be set to 0. 228 229 If command succeeds, ii_handle contains a handle that should be used 230 with other isochronous commands. ii_frame_rcnt contains the number of 231 allocated frames (can be less than ii_frame_cnt). ii_mmap_off 232 contains an offset to be used in mmap(2), for example, to map an 233 entire data receive buffer: 234 235 pa = mmap(NULL, init.ii_pkt_size * 236 init.ii_frame_size * init.ii_frame_rcnt, 237 PROT_READ, MAP_PRIVATE, fd, init.ii_mmap_off); 238 239 ii_rchannel contains channel number. 240 241 In case of command success, ii_error is set to 0; otherwise one of the 242 following values can be returned: 243 244 IEC61883_ERR_NOMEM Not enough memory for the data buffer. 245 246 IEC61883_ERR_NOCHANNEL Cannot allocate isochronous channel. 247 248 IEC61883_ERR_PKT_SIZE Packet size is not allowed at this bus speed. 249 250 IEC61883_ERR_VERSION Interface version is not supported. 251 252 IEC61883_ERR_INVAL One or more the parameters are invalid 253 254 IEC61883_ERR_OTHER Unspecified error type. 255 256 IEC61883_ISOCH_FINI 257 258 Argument is a handle returned by IEC61883_ISOCH_INIT. This command 259 frees any resources associated with this handle. There must be no 260 active transfers and the data buffer must be unmapped; otherwise the 261 command fails. 262 263 IEC61883_START 264 265 This command starts an isochronous transfer. The argument is a handle 266 returned by IEC61883_ISOCH_INIT. 267 268 IEC61883_STOP 269 270 This command stops an isochronous transfer. The argument is a handle 271 returned by IEC61883_ISOCH_INIT. 272 273 IEC61883_RECV 274 275 This command is used to receive full frames and return empty frames to 276 the driver. The argument is a pointer to the structure: 277 278 typedef struct iec61883_recv { 279 int rx_handle; /* isoch handle */ 280 int rx_flags; /* flags */ 281 iec61883_xfer_t rx_xfer; /* xfer params */ 282 } iec61883_recv_t; 283 284 typedef struct iec61883_xfer { 285 int xf_empty_idx; /* first empty frame */ 286 int xf_empty_cnt; /* empty frame count */ 287 int xf_full_idx; /* first full frame */ 288 int xf_full_cnt; /* full frame count */ 289 int xf_error; /* error */ 290 } iec61883_xfer_t; 291 292 rx_flags should be set to 0. 293 294 An application sets xf_empty_idx and xf_empty_cnt to indicate frames 295 it no longer needs. E. g. if a buffer consists of 6 frames, 296 xf_empty_idx is 4, xf_empty_cnt is 3 - means that frames 4, 5 and 0 297 can now be reused by the driver. If there are no empty frames, for 298 example, the first time this command is called, xf_empty_cnt should be 299 set to 0. 300 301 When the command returns, xf_full_idx and xf_full_cnt specifies the 302 frames that are full. xf_error is always 0. 303 304 In general, AV frame boundaries are not aligned with the frame buffer 305 boundaries, because the first received packet might not be the first 306 packet of an AV frame, and, in contrast with the read/write method, 307 the driver does not remove empty CIP packets. 308 309 Applications should detect empty packets by comparing adjacent 310 packets' continuity counters (DBC field of the CIP header). 311 312 IEC61883_XMIT 313 314 This command is used to transmit full frames and get more empty frames 315 from the driver. The argument is a pointer to the structure: 316 317 typedef struct iec61883_xmit { 318 int tx_handle; /* isoch handle */ 319 int tx_flags; /* flags */ 320 iec61883_xfer_t tx_xfer; /* xfer params */ 321 int tx_miss_cnt; /* missed cycles */ 322 } iec61883_xmit_t; 323 324 tx_flags should be set to zero. 325 326 The application sets xf_full_idx and xf_full_cnt to specify frames it 327 wishes to transmit. If there are no frames to transmit (e. g. the 328 first time this command is called), xf_full_cnt should be set to 0. 329 330 When the command returns, xf_empty_idx and xf_empty_cnt specifies 331 empty frames which can be to transmit more data. xf_error is always 332 0. 333 334 tx_miss_cnt contains the number of isochronous cycles missed since 335 last transfer due to data buffer under run. This can happen when an 336 application does not supply data fast enough. For the purposes of 337 time stamping, the driver considers the first packet in a frame buffer 338 to be the first packet of an AV frame. 339 340 IEC61883_PLUG_INIT 341 342 This command returns a handle for the specified plug. The argument is 343 a pointer to the structure: 344 345 typedef struct iec61883_plug_init { 346 int pi_ver; /* interface version */ 347 int pi_loc; /* plug location */ 348 int pi_type; /* plug type */ 349 int pi_num; /* plug number */ 350 int pi_flags; /* flags */ 351 int pi_handle; /* plug handle */ 352 int pi_rnum; /* plug number */ 353 } iec61883_plug_init_t; 354 355 pi_ver should be set to IEC61883_V1_0. 356 357 pi_loc specifies plug location: 358 359 IEC61883_LOC_LOCAL On the local unit (local plug). A plug control 360 register (PCR) is allocated. Command fails if 361 the plug already exists 362 363 IEC61883_LOC_REMOTE On the remote unit (remote plug). The plug 364 should exist on the remote unit, otherwise the 365 command fails. 366 367 pi_type specifies isochronous plug type: 368 369 IEC61883_PLUG_IN 370 IEC61883_PLUG_OUT 371 372 Input or output plugs. 373 374 IEC61883_PLUG_MASTER_IN 375 IEC61883_PLUG_MASTER_OUT 376 377 Master input or master output plug. These plugs always exist on 378 the local unit. 379 380 pi_num specifies plug number. This should be 0 for master plugs, and 381 from 0 to 31 for input/output plugs. Alternatively, a special value 382 IEC61883_PLUG_ANY can be used to let the driver choose a free plug 383 number, create the plug and return the number in pi_rnum. 384 385 pi_flags should be set to 0. 386 387 If the command succeeds, pi_handle contains a handle that should be 388 used with other plug commands. 389 390 IEC61883_PLUG_FINI 391 392 Argument is a handle returned by IEC61883_PLUG_INIT. This command 393 frees any resources associated with this handle, including the PCR. 394 395 IEC61883_PLUG_REG_READ 396 397 Read plug register value. The argument is a pointer to the structure: 398 399 typedef struct iec61883_plug_reg_val { 400 int pr_handle; /* plug handle */ 401 uint32_t pr_val; /* register value */ 402 } iec61883_plug_reg_val_t; 403 404 pr_handle is a handle returned by IEC61883_PLUG_INIT. Register value 405 is returned in pr_val. 406 407 IEC61883_PLUG_REG_CAS 408 409 Atomically compare and swap plug register value. The argument is a 410 pointer to the structure: 411 412 typedef struct iec61883_plug_reg_lock { 413 int pl_handle; /* plug handle */ 414 uint32_t pl_arg; /* compare arg */ 415 uint32_t pl_data; /* write value */ 416 UINT32_t pl_old; /* original value */ 417 } iec61883_plug_reg_lock_t; 418 419 pr_handle is a handle returned by IEC61883_PLUG_INIT. 420 421 Original register value is compared with pl_arg and if they are equal, 422 register value is replaced with pl_data. In any case, the original 423 value is stored in pl_old. 424 425 The following commands only apply to asynchronous nodes: 426 427 IEC61883_ARQ_GET_IBUF_SIZE 428 429 This command returns current incoming ARQ buffer size. The argument 430 is a pointer to int. 431 432 IEC61883_ARQ_SET_IBUF_SIZE 433 434 This command changes incoming ARQ buffer size. The argument is the 435 new buffer size in bytes. 436 437 FILES 438 /dev/av/N/async Device node for asynchronous data 439 440 /dev/av/N/isoch Device has been disconnected 441 442 ERRORS 443 EIO Bus operation failed. DMA failure. 444 445 EFAULT ioctl(2) argument points to an illegal address. 446 447 EINVAL Invalid argument or argument combination. 448 449 ENODEV Device has been disconnected. 450 451 ARCHITECTURE 452 All 453 454 INTERFACE STABILITY 455 Committed 456 457 SEE ALSO 458 ioctl(2), mmap(2), open(2), poll(2), read(2), write(2), attributes(5), 459 av1394(7D) 460 461 IIEC 61883 Consumer audio/video equipment - Digital interface. 462 463 IEEE Std 1394-1995 Standard for a High Performance Serial Bus. 464 465 illumos July 9, 2018 illumos