1 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved 2 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. 3 .\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the 4 .\" fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] 5 .Dd July 9, 2018 6 .Dt IEC61883 7I 7 .Os 8 .Sh NAME 9 .Nm iec61883 10 .Nd IEC 61883 interfaces 11 .Sh SYNOPSIS 12 .In sys/av/iec61883.h 13 .Sh DESCRIPTION 14 The set of interfaces described in this man page can be used to control and 15 exchange data with consumer audio/video devices using protocols specified 16 in 17 .%T "IIEC 61883 Consumer Electronic Audio/Video Equipment - Digital Interface" 18 including Common Isochronous Packet (CIP), Connection Management 19 Procedures (CMP) and Function Control Protocol (FCP). 20 .Pp 21 An 22 .Nm 23 compliant driver exports two device nodes for isochronous and 24 for asynchronous transactions. 25 See the 26 .Sx FILES 27 section of this man page for the namespace definition. 28 .Ss "Isochronous Transfers" 29 Two methods are provided to receive/transmit isochronous data: using 30 .Xr mmap 2 31 in combination with 32 .Xr ioctl 2 , 33 and 34 .Xr read 2 35 or 36 .Xr write 2 . 37 .Ss "Mmap/Ioctl" 38 This method provides better performance and finer-grained control than 39 read/write, and is a method of choice for most applications. 40 The data buffer is 41 mapped into a user process address space, which means no data copying between 42 the kernel and an application is necessary. 43 Synchronization between user 44 processes and the driver is performed using 45 .Xr ioctl 2 46 commands. 47 .Pp 48 An application allocates resources for isochronous transfer using 49 .Dv IEC61883_ISOCH_INIT . 50 Then the data buffer can be mapped into the process 51 space using 52 .Xr mmap 2 . 53 .Pp 54 A circular data buffer consists of one or more equal size frame buffers 55 (further referred to as frames, unless to avoid ambiguity with AV frames). 56 Frames are numbered starting with zero and are always transferred sequentially. 57 Frames consist equal sized packets. 58 Each packet contains a CIP header and one or more data blocks. 59 .Pp 60 A driver and an application act as a producer and a consumer: producer supplies 61 .Em full 62 frames (filled with data) to the consumer, and the producer is not 63 allowed to access those frames until the consumer claims them 64 .Em empty . 65 .Pp 66 A transfer can be initiated and suspended with 67 .Dv IEC61883_START 68 and 69 .Dv IEC61883_STOP 70 commands respectively. 71 .Dv IEC61883_RECV 72 or 73 .Dv IEC61883_XMIT 74 is used for producer-consumer synchronization. 75 .Ss "Read/Write" 76 Using this method, an application calls 77 .Xr read 2 78 or 79 .Xr write 2 80 to receive or transmit a specified amount of data. 81 Bus-specific overhead, such as isochronous packet headers, is handled by the driver 82 and is not exposed to applications. 83 Data returned by 84 .Xr read 2 85 contains CIP headers and data blocks. 86 Empty packets are not returned by 87 .Xr read 2 . 88 .Xr write 2 89 data should meet the same requirements. 90 .Pp 91 If one or more channels have been allocated since 92 .Xr open 2 93 (see 94 .Dv IEC61883_ISOCH_INIT ) , 95 the data is received/transmitted using channel that was created the last. 96 .Pp 97 If no channels were allocated, the driver uses the broadcast channel by default 98 and allocates the default-size data buffer. 99 During transmit, the first packet's CIP header is used to auto-detect the data format. 100 If it is one of the formats supported by the driver, it is properly transmitted (with 101 inserted empty packets and timestamps). 102 .Pp 103 For both methods, if during transmit the driver runs out of data, it transmits 104 empty packets containing only a CIP header of the next to be transmitted 105 packet, as defined in 106 .Em IEC 61883-1 . 107 .Ss "Connection Management Procedures" 108 Applications wishing to follow Connection Management Procedures (CMP) in 109 combination with isochronous transfers should use the 110 .Xr ioctl 2 111 .Dv IEC61883_PLUG_INIT , 112 .Dv IEC61883_PLUG_FINI , 113 .Dv IEC61883_PLUG_REG_READ 114 and 115 .Dv IEC61883_PLUG_REG_CAS 116 commands. 117 .Ss "Asynchronous Transactions" 118 .Xr read 2 , 119 .Xr write 2 , 120 .Xr ioctl 2 , 121 and 122 .Xr poll 2 123 can be used 124 with asynchronous nodes. 125 Asynchronous data exchange between a driver and an 126 application utilizes a common data structure called asynchronous request (ARQ): 127 .Bd -literal -offset 2n 128 typedef struct iec61883_arq { 129 int arq_type; 130 int arq_len; 131 union { 132 uint32_t quadlet; 133 uint64_t octlet; 134 uint8_t buf[8]; 135 } arq_data; 136 } iec61883_arq_t; 137 .Ed 138 .Pp 139 .Fa arq_type 140 contains 141 .Sy ARQ 142 type: 143 .Pp 144 .Bl -tag -width " " -compact 145 .It Dv IEC61883_ARQ_FCP_CMD 146 .It Dv IEC61883_ARQ_FCP_RESP 147 .Pp 148 .Sy FCP 149 command and response frame respectively. 150 Outgoing frames are sent using 151 .Xr write 2 , 152 incoming frames are received with 153 .Xr read 2 . 154 .Pp 155 See 156 .Em IIEC 61883-1 157 for the FCP frame structure definition. 158 .Pp 159 .It Dv IEC61883_ARQ_BUS_RESET 160 .Pp 161 Returned by the driver when a bus reset occurs. 162 There is no data associated with this request type, and \fBarq_len\fR is set to 0. 163 .El 164 .Pp 165 If 166 .Fa arq_len 167 is 4 or 8, then data should be supplied in 168 .Fa arq_data.quadlet 169 or 170 .Fa arq_data.octlet 171 respectively, otherwise up to 8 bytes can be put in 172 .Fa arq_data.buf , 173 with the rest of the data following immediately after. 174 .Ss "write(2)" 175 For a request to be sent to a target, an 176 .Vt iec61883_arq_t 177 structure along with associated data is passed to the driver using 178 .Xr write 2 . 179 .Xr write 2 180 blocks until the request is completed. 181 .Ss "read(2)" 182 A driver collects incoming ARQs in the internal buffer. 183 Buffer size can be changed using the 184 .Xr ioctl 2 185 command 186 .Vt IEC61883_FCP_SET_IBUF_SIZE . 187 .Pp 188 Reading an ARQ takes one or two steps depending on data length. 189 An application 190 first reads 191 .Ql sizeof (iec61883_arq_t) 192 bytes: if 193 .Fa arq_len 194 is less than or equal 4, which is usually the case, no additional step is needed. 195 Otherwise, 196 the remaining 197 .Ql arq_len - 4 198 bytes should be read and concatenated. 199 .Pp 200 .Xr read 2 201 blocks until the specified amount of data is available, unless 202 .Dv O_NONBLOCK 203 or 204 .Dv O_NDELAY 205 flag was set during 206 .Xr open 2 , 207 in which case 208 .Xr read 2 209 returns immediately. 210 .Ss "poll(2)" 211 Applications can 212 .Xr poll 2 213 asynchronous nodes on the 214 .Dv POLLIN 215 event. 216 .Ss "Bus Reset" 217 In case of a bus reset, the driver notifies an application by generating an 218 .Sy ARQ 219 of type 220 .Dv IEC61883_ARQ_BUS_RESET . 221 .Pp 222 If there were established isochronous connections before bus reset, the driver 223 attempts to restore all connections as described in 224 .Em IEC 61883 225 and resume any active transfers that were in progress. 226 .Sh IOCTLS 227 The following commands only apply to isochronous nodes: 228 .Bl -tag -width " " 229 .It Dv IEC61883_ISOCH_INIT 230 .Pp 231 This command allocates a data buffer and isochronous resources (if necessary) 232 for the isochronous transfer. 233 The argument is a pointer to the structure: 234 .Bd -literal -offset 2n 235 typedef struct iec61883_isoch_init { 236 int ii_version; /* interface version */ 237 int ii_pkt_size; /* packet size */ 238 int ii_frame_size; /* packets/frame */ 239 int ii_frame_cnt; /* # of frames */ 240 int ii_direction; /* xfer direction */ 241 int ii_bus_speed; /* bus speed */ 242 uint64_t ii_channel; /* channel mask */ 243 int ii_dbs; /* DBS */ 244 int ii_fn; /* FN */ 245 int ii_rate_n; /* rate numerator */ 246 int ii_rate_d; /* rate denominator */ 247 int ii_ts_mode; /* timestamp mode */ 248 int ii_flags; /* flags */ 249 int ii_handle; /* isoch handle */ 250 int ii_frame_rcnt; /* # of frames */ 251 off_t *ii_mmap_off /* mmap offset */ 252 int ii_rchannel; /* channel */ 253 int ii_error; /* error code */ 254 } iec61883_isoch_init_t; 255 .Ed 256 .Pp 257 .Fa ii_version 258 should be set to 259 .Dv IEC61883_V1_0 . 260 .Pp 261 The driver attempts to allocate a data buffer consisting of 262 .Fa ii_frame_cnt 263 frames, with 264 .Fa ii_frame_size 265 packets in each frame. 266 Packet size in bytes is specified by 267 .Fa ii_pkt_size 268 specifies and should be a multiple of 512 and compatible with 269 .Fa ii_bus_speed . 270 .Pp 271 .Fa ii_direction 272 can take one of the following values: 273 .Bl -tag -width "IEC61883_DIR_RECV" 274 .It Dv IEC61883_DIR_RECV 275 Receiving isochronous data. 276 .It Dv IEC61883_DIR_XMIT 277 Transmitting isochronous data. 278 .El 279 .Pp 280 .Fa ii_bus_speed 281 chooses bus speed to be used and can be either 282 .Dv IEC61883_S100 , 283 .Dv IEC61883_S200 284 or 285 .Dv IEC61883_S400 . 286 .Pp 287 .Fa ii_channel 288 is a mask that specifies an isochronous channel number to be 289 used, with the 290 .Em N Ns th 291 bit representing channel 292 .Em N . 293 When transmitting data, several bits can be set at a time, in which case the 294 driver chooses one, for example, 295 .Sy 0x3FF 296 means a range from 0 to 9. 297 In case of receive, only one bit can be set. 298 .Pp 299 .Fa ii_dbs 300 specifies data block size in quadlets, for example, DBS value for 301 .Dv SD-DVCR 302 is 303 .Sy 0x78 . 304 Refer to 305 .Em IEC 61883 306 for more details on DBS. 307 .Pp 308 .Fa ii_fn 309 specifies fraction number, which defines the number of blocks in which a 310 source packet is divided. 311 Allowed values are from 0 to 3. 312 Refer to 313 .Em IEC 61883 314 for more details on FN. 315 .Pp 316 Data rate expected by the AV device can be lower than the bus speed, in which 317 case the driver has to periodically insert empty packets into the data stream 318 to avoid device buffer overflows. 319 This rate is specified with a fraction N/D, 320 set by 321 .Fa ii_rate_n 322 and 323 .Fa ii_rate_d 324 respectively. 325 Any integer numbers can be used, or the following predefined constants: 326 .Pp 327 .Bl -tag -width "IEC61883_RATE_N_DV_NTSC" -compact 328 .It Dv IEC61883_RATE_N_DV_NTSC 329 .It Dv IEC61883_RATE_D_DV_NTSC 330 Data rate expected by 331 .Sy DV-NTSC 332 devices. 333 .Pp 334 .It Dv IEC61883_RATE_N_DV_PAL 335 .It Dv IEC61883_RATE_D_DV_PAL 336 Data rate expected by 337 .Sy DV-PAL 338 devices. 339 .El 340 .Pp 341 During data transmission, a timestamp based on the current value of the cycle 342 timer is usually required. 343 .Fa ii_ts_mode 344 defines timestamp mode to be used: 345 .Bl -tag -width IEC61883_TS_NONE 346 .It Dv IEC61883_TS_SYT 347 Driver puts a timestamp in the SYT field of the first CIP header of each frame. 348 .It Dv IEC61883_TS_NONE 349 No timestamps. 350 .El 351 .Pp 352 .Fa ii_dbs , 353 .Fa ii_fn , 354 .Fa ii_rate_n , 355 .Fa ii_rate_d 356 and 357 .Fa ii_ts_mode 358 are only required for transmission. 359 In other case these should be set to 0. 360 .Pp 361 .Fa ii_flags 362 should be set to 0. 363 .Pp 364 If command succeeds, 365 .Fa ii_handle 366 contains a handle that should be used with other isochronous commands. 367 .Fa ii_frame_rcnt 368 contains the number of allocated frames (can be less than 369 .Fa ii_frame_cnt ) . 370 .Fa ii_mmap_off 371 contains an offset to be used in 372 .Xr mmap 2 , 373 for example, to map an entire data receive buffer: 374 .Bd -literal -offset 2n 375 pa = mmap(NULL, init.ii_pkt_size * 376 init.ii_frame_size * init.ii_frame_rcnt, 377 PROT_READ, MAP_PRIVATE, fd, init.ii_mmap_off); 378 .Ed 379 .Pp 380 .Fa ii_rchannel 381 contains channel number. 382 .Pp 383 In case of command success, 384 .Fa ii_error 385 is set to 0; otherwise one of the following values can be returned: 386 .Bl -tag -width IEC61883_ERR_NOCHANNEL 387 .It Dv IEC61883_ERR_NOMEM 388 Not enough memory for the data buffer. 389 .It Dv IEC61883_ERR_NOCHANNEL 390 Cannot allocate isochronous channel. 391 .It Dv IEC61883_ERR_PKT_SIZE 392 Packet size is not allowed at this bus speed. 393 .It Dv IEC61883_ERR_VERSION 394 Interface version is not supported. 395 .It Dv IEC61883_ERR_INVAL 396 One or more the parameters are invalid 397 .It Dv IEC61883_ERR_OTHER 398 Unspecified error type. 399 .El 400 .It Dv IEC61883_ISOCH_FINI 401 .Pp 402 Argument is a handle returned by 403 .Dv IEC61883_ISOCH_INIT . 404 This command frees any resources associated with this handle. 405 There must be no active transfers 406 and the data buffer must be unmapped; otherwise the command fails. 407 .It Dv IEC61883_START 408 .Pp 409 This command starts an isochronous transfer. 410 The argument is a handle returned 411 by 412 .Dv IEC61883_ISOCH_INIT . 413 .It Dv IEC61883_STOP 414 .Pp 415 This command stops an isochronous transfer. 416 The argument is a handle returned by 417 .Dv IEC61883_ISOCH_INIT . 418 .It Dv IEC61883_RECV 419 .Pp 420 This command is used to receive full frames and return empty frames to the driver. 421 The argument is a pointer to the structure: 422 .Bd -literal -offset 2n 423 typedef struct iec61883_recv { 424 int rx_handle; /* isoch handle */ 425 int rx_flags; /* flags */ 426 iec61883_xfer_t rx_xfer; /* xfer params */ 427 } iec61883_recv_t; 428 429 typedef struct iec61883_xfer { 430 int xf_empty_idx; /* first empty frame */ 431 int xf_empty_cnt; /* empty frame count */ 432 int xf_full_idx; /* first full frame */ 433 int xf_full_cnt; /* full frame count */ 434 int xf_error; /* error */ 435 } iec61883_xfer_t; 436 .Ed 437 .Pp 438 .Fa rx_flags 439 should be set to 0. 440 .Pp 441 An application sets 442 .Fa xf_empty_idx 443 and 444 .Fa xf_empty_cnt 445 to indicate frames it no longer needs. 446 E. g. if a buffer consists of 6 frames, 447 .Fa xf_empty_idx 448 is 4, 449 .Fa xf_empty_cnt 450 is 3 - means that frames 4, 5 and 0 can now be reused by the driver. 451 If there are no empty frames, for example, the 452 first time this command is called, 453 .Fa xf_empty_cnt 454 should be set to 0. 455 .Pp 456 When the command returns, 457 .Fa xf_full_idx 458 and 459 .Fa xf_full_cnt 460 specifies the frames that are full. 461 .Fa xf_error 462 is always 0. 463 .Pp 464 In general, AV frame boundaries are not aligned with the frame buffer 465 boundaries, because the first received packet might not be the first packet of 466 an AV frame, and, in contrast with the read/write method, the driver does not 467 remove empty CIP packets. 468 .Pp 469 Applications should detect empty packets by comparing adjacent packets' 470 continuity counters (DBC field of the CIP header). 471 .It Dv IEC61883_XMIT 472 .Pp 473 This command is used to transmit full frames and get more empty frames from the 474 driver. 475 The argument is a pointer to the structure: 476 .Bd -literal -offset 2n 477 typedef struct iec61883_xmit { 478 int tx_handle; /* isoch handle */ 479 int tx_flags; /* flags */ 480 iec61883_xfer_t tx_xfer; /* xfer params */ 481 int tx_miss_cnt; /* missed cycles */ 482 } iec61883_xmit_t; 483 .Ed 484 .Pp 485 .Fa tx_flags 486 should be set to zero. 487 .Pp 488 The application sets 489 .Fa xf_full_idx 490 and 491 .Fa xf_full_cnt 492 to specify frames it wishes to transmit. 493 If there are no frames to transmit (e. g. the first time this command is called), 494 .Fa xf_full_cnt 495 should be set to 0. 496 .Pp 497 When the command returns, 498 .Fa xf_empty_idx 499 and 500 .Fa xf_empty_cnt 501 specifies empty frames which can be to transmit more data. 502 .Fa xf_error 503 is always 0. 504 .Pp 505 .Fa tx_miss_cnt 506 contains the number of isochronous cycles missed since last 507 transfer due to data buffer under run. 508 This can happen when an application does not supply data fast enough. 509 For the purposes of time stamping, the driver considers the first packet in a 510 frame buffer to be the first packet of an AV frame. 511 .It Dv IEC61883_PLUG_INIT 512 .Pp 513 This command returns a handle for the specified plug. 514 The argument is a pointer 515 to the structure: 516 .Bd -literal -offset 2n 517 typedef struct iec61883_plug_init { 518 int pi_ver; /* interface version */ 519 int pi_loc; /* plug location */ 520 int pi_type; /* plug type */ 521 int pi_num; /* plug number */ 522 int pi_flags; /* flags */ 523 int pi_handle; /* plug handle */ 524 int pi_rnum; /* plug number */ 525 } iec61883_plug_init_t; 526 .Ed 527 .Pp 528 .Fa pi_ver 529 should be set to 530 .Dv IEC61883_V1_0 . 531 .Pp 532 .Fa pi_loc 533 specifies plug location: 534 .Bl -tag -width IEC61883_LOC_REMOTE 535 .It Dv IEC61883_LOC_LOCAL 536 On the local unit (local plug). 537 A plug control register (PCR) is allocated. 538 Command fails if the plug already exists 539 .It Dv IEC61883_LOC_REMOTE 540 On the remote unit (remote plug). 541 The plug should exist on the remote unit, 542 otherwise the command fails. 543 .El 544 .Pp 545 .Fa pi_type 546 specifies isochronous plug type: 547 .Pp 548 .Bl -tag -width " " -compact 549 .It Dv IEC61883_PLUG_IN 550 .It Dv IEC61883_PLUG_OUT 551 .Pp 552 Input or output plugs. 553 .Pp 554 .It Dv IEC61883_PLUG_MASTER_IN 555 .It Dv IEC61883_PLUG_MASTER_OUT 556 .Pp 557 Master input or master output plug. 558 These plugs always exist on the local unit. 559 .El 560 .Pp 561 .Fa pi_num 562 specifies plug number. 563 This should be 0 for master plugs, and from 0 to 31 for input/output plugs. 564 Alternatively, a special value 565 .Dv IEC61883_PLUG_ANY 566 can be used to let the driver choose a free plug 567 number, create the plug and return the number in 568 .Fa pi_rnum . 569 .Pp 570 .Fa pi_flags 571 should be set to 0. 572 .Pp 573 If the command succeeds, 574 .Fa pi_handle 575 contains a handle that should be used with other plug commands. 576 .It Dv IEC61883_PLUG_FINI 577 .Pp 578 Argument is a handle returned by 579 .Dv IEC61883_PLUG_INIT . 580 This command frees any resources associated with this handle, including the PCR. 581 .It Dv IEC61883_PLUG_REG_READ 582 .Pp 583 Read plug register value. 584 The argument is a pointer to the structure: 585 .Bd -literal -offset 2n 586 typedef struct iec61883_plug_reg_val { 587 int pr_handle; /* plug handle */ 588 uint32_t pr_val; /* register value */ 589 } iec61883_plug_reg_val_t; 590 .Ed 591 .Pp 592 .Fa pr_handle 593 is a handle returned by 594 .Dv IEC61883_PLUG_INIT . 595 Register 596 value is returned in 597 .Fa pr_val . 598 .It Dv IEC61883_PLUG_REG_CAS 599 .Pp 600 Atomically compare and swap plug register value. 601 The argument is a pointer to the structure: 602 .Bd -literal -offset 2n 603 typedef struct iec61883_plug_reg_lock { 604 int pl_handle; /* plug handle */ 605 uint32_t pl_arg; /* compare arg */ 606 uint32_t pl_data; /* write value */ 607 UINT32_t pl_old; /* original value */ 608 } iec61883_plug_reg_lock_t; 609 .Ed 610 .Pp 611 .Fa pr_handle 612 is a handle returned by IEC61883_PLUG_INIT. 613 .Pp 614 Original register value is compared with 615 .Fa pl_arg 616 and if they are equal, register value is replaced with 617 .Fa pl_data . 618 In any case, the original value is stored in 619 .Fa pl_old . 620 .El 621 .Pp 622 The following commands only apply to asynchronous nodes: 623 .Bl -tag -width " " 624 .It Dv IEC61883_ARQ_GET_IBUF_SIZE 625 .Pp 626 This command returns current incoming ARQ buffer size. 627 The argument is a 628 pointer to 629 .Vt int . 630 .It Dv IEC61883_ARQ_SET_IBUF_SIZE 631 .Pp 632 This command changes incoming ARQ buffer size. 633 The argument is the new buffer 634 size in bytes. 635 .El 636 .Sh FILES 637 .Bl -tag -width /dev/av/N/async 638 .It Pa /dev/av/N/async 639 Device node for asynchronous data 640 .It Pa /dev/av/N/isoch 641 Device has been disconnected 642 .El 643 .Sh ERRORS 644 .Bl -tag -width EFAULT 645 .It Er EIO 646 Bus operation failed. 647 DMA failure. 648 .It Er EFAULT 649 .Xr ioctl 2 650 argument points to an illegal address. 651 .It Er EINVAL 652 Invalid argument or argument combination. 653 .It Er ENODEV 654 Device has been disconnected. 655 .El 656 .Sh ARCHITECTURE 657 All 658 .Sh INTERFACE STABILITY 659 Committed 660 .Sh SEE ALSO 661 .Xr ioctl 2 , 662 .Xr mmap 2 , 663 .Xr open 2 , 664 .Xr poll 2 , 665 .Xr read 2 , 666 .Xr write 2 , 667 .Xr attributes 5 , 668 .Xr av1394 7D 669 .Rs 670 .%B IIEC 61883 Consumer audio/video equipment - Digital interface 671 .Re 672 .Rs 673 .%B IEEE Std 1394-1995 Standard for a High Performance Serial Bus 674 .Re