Merge commit 'b31ca922c7346747131aed07c0c171ec2f573aac' into merges
[unleashed.git] / share / man / man7i / iec61883.7i
blobfd30ad7a7b7590233c5da6f9ebe84cb504246ae8
1 '\" te
2 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved
3 .\" 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.
4 .\"  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
5 .\" fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH IEC61883 7I "Mar 27, 2009"
7 .SH NAME
8 iec61883 \- IEC 61883 interfaces
9 .SH SYNOPSIS
10 .LP
11 .nf
12 #include <sys/av/iec61883.h>
13 .fi
15 .SH DESCRIPTION
16 .sp
17 .LP
18 The set of interfaces described in this man page can be used to control and
19 exchange data with consumer audio/video devices using protocols specified
20 in\fIIEC 61883 Consumer Electronic Audio/Video Equipment - Digital
21 Interface\fR, including Common Isochronous Packet (CIP), Connection Management
22 Procedures (CMP) and Function Control Protocol (FCP).
23 .sp
24 .LP
25 An \fBiec61883\fR compliant driver exports two device nodes for isochronous and
26 for asynchronous transactions. See the \fBFILES\fR section of this man page for
27 the namespace definition.
28 .SS "Isochronous Transfers"
29 .sp
30 .LP
31 Two methods are provided to receive/transmit isochronous data: using
32 \fBmmap\fR(2) in combination with \fBioctl\fR(2), and \fBread\fR(2) or
33 \fBwrite\fR(2).
34 .SS "Mmap/Ioctl"
35 .sp
36 .LP
37 This method provides better performance and finer-grained control than
38 read/write, and is a method of choice for most applications. The data buffer is
39 mapped into a user process address space, which means no data copying between
40 the kernel and an application is necessary. Synchronization between user
41 processes and the driver is performed using \fBioctl\fR(2) commands.
42 .sp
43 .LP
44 An application allocates resources for isochronous transfer using
45 \fBIEC61883_ISOCH_INIT\fR. Then the data buffer can be mapped into the process
46 space using \fBmmap\fR(2).
47 .sp
48 .LP
49 A circular data buffer consists of one or more equal size frame buffers
50 (further referred to as frames, unless to avoid ambiguity with AV frames).
51 Frames are numbered starting with zero and are always transferred sequentially.
52 Frames consist equal sized packets. Each packet contains a CIP header and one
53 or more data blocks.
54 .sp
55 .LP
56 A driver and an application act as a producer and a consumer: producer supplies
57 \fBfull\fR frames (filled with data) to the consumer, and the producer is not
58 allowed to access those frames until the consumer claims them \fBempty\fR.
59 .sp
60 .LP
61 A transfer can be initiated and suspended with \fBIEC61883_START\fR and
62 \fBIEC61883_STOP\fR commands respectively. \fBIEC61883_RECV\fR or
63 \fBIEC61883_XMIT\fR is used for producer-consumer synchronization.
64 .SS "Read/Write"
65 .sp
66 .LP
67 Using this method, an application calls \fBread\fR(2) or \fBwrite\fR(2) to
68 receive or transmit a specified amount of data. Bus-specific overhead, such as
69 isochronous packet headers, is handled by the driver and is not exposed to
70 applications. Data returned by \fBread\fR(2) contains CIP headers and data
71 blocks. Empty packets are not returned by \fBread\fR(2). \fBwrite\fR(2) data
72 should meet the same requirements.
73 .sp
74 .LP
75 If one or more channels have been allocated since \fBopen\fR(2) (see
76 \fBIEC61883_ISOCH_INIT\fR), the data is received/transmitted using channel that
77 was created the last.
78 .sp
79 .LP
80 If no channels were allocated, the driver uses the broadcast channel by default
81 and allocates the default-size data buffer. During transmit, the first packet's
82 CIP header is used to auto-detect the data format. If it is one of the formats
83 supported by the driver, it is properly transmitted (with inserted empty
84 packets and timestamps).
85 .sp
86 .LP
87 For both methods, if during transmit the driver runs out of data, it transmits
88 empty packets containing only a CIP header of the next to be transmitted
89 packet, as defined in \fIIEC 61883-1\fR.
90 .SS "Connection Management Procedures"
91 .sp
92 .LP
93 Applications wishing to follow Connection Management Procedures (CMP) in
94 combination with isochronous transfers should use the \fBioctl\fR(2)
95 \fBIEC61883_PLUG_INIT, IEC61883_PLUG_FINI, IEC61883_PLUG_REG_READ\fR and
96 \fBIEC61883_PLUG_REG_CAS\fR commands.
97 .SS "Asynchronous Transactions"
98 .sp
99 .LP
100 \fBread\fR(2), \fBwrite\fR(2), \fBioctl\fR(2), and \fBpoll\fR(2) can be used
101 with asynchronous nodes. Asynchronous data exchange between a driver and an
102 application utilizes a common data structure called asynchronous request (ARQ):
104 .in +2
106 typedef struct iec61883_arq {
107         int        arq_type;
108         int        arq_len;
109         union {
110                 uint32_t   quadlet;
111                 uint64_t   octlet;
112                 uint8_t    buf[8];
113         } arq_data;
114 } iec61883_arq_t;
116 .in -2
121 \fBarq_type\fR contains \fBARQ\fR type:
123 .ne 2
125 \fB\fBIEC61883_ARQ_FCP_CMD\fR\fR
129 \fB\fBIEC61883_ARQ_FCP_RESP\fR\fR
131 .sp .6
132 .RS 4n
133 \fBFCP\fR command and response frame respectively. Outgoing frames are sent
134 using \fBwrite\fR(2), incoming frames are received with \fBread\fR(2).
136 See \fIIEC 61883-1\fR for the FCP frame structure definition.
140 .ne 2
142 \fB\fBIEC61883_ARQ_BUS_RESET\fR\fR
144 .sp .6
145 .RS 4n
146 Returned by the driver when a bus reset occurs. There is no data associated
147 with this request type, and \fBarq_len\fR is set to 0.
152 If \fBarq_len\fR is 4 or 8, then data should be supplied in
153 \fBarq_data.quadlet\fR or \fBarq_data.octlet\fR respectively, otherwise up to 8
154 bytes can be put in \fBarq_data.buf\fR, with the rest of the data following
155 immediately after.
156 .SS "write(2)"
159 For a request to be sent to a target, an \fBiec61883_arq_t\fR structure along
160 with associated data is passed to the driver using \fBwrite\fR(2).
161 \fBwrite()\fR blocks until the request is completed.
162 .SS "read(2)"
165 A driver collects incoming ARQs in the internal buffer. Buffer size can be
166 changed using the \fBioctl\fR(2) command \fBIEC61883_FCP_SET_IBUF_SIZE\fR.
169 Reading an ARQ takes one or two steps depending on data length. An application
170 first reads \fBsizeof (iec61883_arq_t)\fR bytes: if \fBarq_len\fR is less than
171 or equal 4, which is usually the case, no additional step is needed. Otherwise,
172 the remaining \fBarq_len - 4\fR bytes should be read and concatenated.
175 \fBread\fR(2) blocks until the specified amount of data is available, unless
176 \fBO_NONBLOCK\fR or \fBO_NDELAY\fR flag was set during \fBopen\fR(2), in which
177 case \fBread\fR(2) returns immediately.
178 .SS "poll(2)"
181 Applications can \fBpoll\fR(2) asynchronous nodes on the \fBPOLLIN\fR event.
182 .SS "Bus Reset"
185 In case of a bus reset, the driver notifies an application by generating an
186 \fBARQ\fR of type \fBIEC61883_ARQ_BUS_RESET\fR.
189 If there were established isochronous connections before bus reset, the driver
190 attempts to restore all connections as described in \fIIEC 61883\fR and resume
191 any active transfers that were in progress.
192 .SH IOCTLS
195 The following commands only apply to isochronous nodes:
197 .ne 2
199 \fB\fBIEC61883_ISOCH_INIT\fR\fR
201 .sp .6
202 .RS 4n
203 This command allocates a data buffer and isochronous resources (if necessary)
204 for the isochronous transfer. The argument is a pointer to the structure:
206 .in +2
208 typedef struct iec61883_isoch_init {
209       int ii_version;       /* interface version */
210       int   ii_pkt_size;    /* packet size */
211       int   ii_frame_size;  /* packets/frame */
212       int   ii_frame_cnt;   /* # of frames */
213       int   ii_direction;   /* xfer direction */
214       int   ii_bus_speed;   /* bus speed */
215       uint64_t ii_channel;  /* channel mask */
216       int   ii_dbs;         /* DBS */
217       int   ii_fn;          /* FN */
218       int   ii_rate_n;      /* rate numerator */
219       int   ii_rate_d;      /* rate denominator */
220       int   ii_ts_mode;     /* timestamp mode */
221       int   ii_flags;       /* flags */
222       int   ii_handle;      /* isoch handle */
223       int   ii_frame_rcnt;  /* # of frames */
224       off_t   *ii_mmap_off  /* mmap offset */
225       int   ii_rchannel;    /* channel */
226       int   ii_error;       /* error code */
227 } iec61883_isoch_init_t;
229 .in -2
232 \fBii_version\fR should be set to \fBIEC61883_V1_0\fR.
234 The driver attempts to allocate a data buffer consisting of \fBii_frame_cnt\fR
235 frames, with \fBii_frame_size\fR packets in each frame. Packet size in bytes is
236 specified by \fBii_pkt_size\fR specifies and should be a multiple of 512 and
237 compatible with \fBii_bus_speed\fR.
239 \fBii_direction\fR can take one of the following values:
241 .ne 2
243 \fB\fBIEC61883_DIR_RECV\fR\fR
245 .sp .6
246 .RS 4n
247 Receiving isochronous data.
251 .ne 2
253 \fB\fBIEC61883_DIR_XMIT\fR\fR
255 .sp .6
256 .RS 4n
257 Transmitting isochronous data.
260 \fBii_bus_speed\fR chooses bus speed to be used and can be either
261 \fBIEC61883_S100, IEC61883_S200\fR or \fBIEC61883_S400\fR.
263 \fBii_channel\fR is a mask that specifies an isochronous channel number to be
264 used, with the \fIN\fRth bit representing channel \fIN\fR. When transmitting
265 data, several bits can be set at a time, in which case the driver chooses one,
266 for example, \fB0x3FF\fR means a range from 0 to 9. In case of receive, only
267 one bit can be set.
269 \fBii_dbs\fR specifies data block size in quadlets, for example, DBS value for
270 \fBSD-DVCR\fR is \fB0x78\fR. Refer to \fIIEC 61883\fR for more details on DBS.
272 ii_fn specifies fraction number, which defines the number of blocks in which a
273 source packet is divided. Allowed values are from 0 to 3. Refer to IEC 61883
274 for more details on FN.
276 Data rate expected by the AV device can be lower than the bus speed, in which
277 case the driver has to periodically insert empty packets into the data stream
278 to avoid device buffer overflows. This rate is specified with a fraction N/D,
279 set by \fBii_rate_n\fR and \fBii_rate_d\fR respectively. Any integer numbers
280 can be used, or the following predefined constants:
282 .ne 2
284 \fB\fBIEC61883_RATE_N_DV_NTSC IEC61883_RATE_D_DV_NTSC\fR\fR
286 .sp .6
287 .RS 4n
288 Data rate expected by \fBDV-NTSC\fR devices.
292 .ne 2
294 \fB\fBIEC61883_RATE_N_DV_PAL IEC61883_RATE_D_DV_PAL\fR\fR
296 .sp .6
297 .RS 4n
298 Data rate expected by \fBDV-PAL\fR devices.
301 During data transmission, a timestamp based on the current value of the cycle
302 timer is usually required. \fBii_ts_mode\fR defines timestamp mode to be used:
304 .ne 2
306 \fB\fBIEC61883_TS_SYT\fR\fR
308 .sp .6
309 .RS 4n
310 Driver puts a timestamp in the SYT field of the first CIP header of each frame.
314 .ne 2
316 \fB\fBIEC61883_TS_NONE\fR\fR
318 .sp .6
319 .RS 4n
320 No timestamps.
323 \fBii_dbs, ii_fn, ii_rate_n, ii_rate_d\fR and \fBii_ts_mode\fR are only
324 required for transmission. In other case these should be set to 0.
326 \fBii_flags\fR should be set to 0.
328 If command succeeds, \fBii_handle\fR contains a handle that should be used with
329 other isochronous commands. \fBii_frame_rcnt\fR contains the number of
330 allocated frames (can be less than \fBii_frame_cnt\fR). \fBii_mmap_off\fR
331 contains an offset to be used in \fBmmap\fR(2), for example, to map an entire
332 data receive buffer:
334 .in +2
336 pa = mmap(NULL, init.ii_pkt_size *
337       init.ii_frame_size * init.ii_frame_rcnt,
338       PROT_READ, MAP_PRIVATE, fd, init.ii_mmap_off);
340 .in -2
343 \fBii_rchannel\fR contains channel number.
345 In case of command success, \fBii_error\fR is set to 0; otherwise one of the
346 following values can be returned:
348 .ne 2
350 \fB\fBIEC61883_ERR_NOMEM\fR\fR
352 .sp .6
353 .RS 4n
354 Not enough memory for the data buffer.
358 .ne 2
360 \fB\fBIEC61883_ERR_NOCHANNEL\fR\fR
362 .sp .6
363 .RS 4n
364 Cannot allocate isochronous channel.
368 .ne 2
370 \fB\fBIEC61883_ERR_PKT_SIZE\fR\fR
372 .sp .6
373 .RS 4n
374 Packet size is not allowed at this bus speed.
378 .ne 2
380 \fB\fBIEC61883_ERR_VERSION\fR\fR
382 .sp .6
383 .RS 4n
384 Interface version is not supported.
388 .ne 2
390 \fB\fBIEC61883_ERR_INVAL\fR\fR
392 .sp .6
393 .RS 4n
394 One or more the parameters are invalid
398 .ne 2
400 \fB\fBIEC61883_ERR_OTHER\fR\fR
402 .sp .6
403 .RS 4n
404 Unspecified error type.
410 .ne 2
412 \fB\fBIEC61883_ISOCH_FINI\fR\fR
414 .sp .6
415 .RS 4n
416 Argument is a handle returned by \fBIEC61883_ISOCH_INIT\fR. This command frees
417 any resources associated with this handle. There must be no active transfers
418 and the data buffer must be unmapped; otherwise the command fails.
422 .ne 2
424 \fB\fBIEC61883_START\fR\fR
426 .sp .6
427 .RS 4n
428 This command starts an isochronous transfer. The argument is a handle returned
429 by \fBIEC61883_ISOCH_INIT\fR.
433 .ne 2
435 \fB\fBIEC61883_STOP\fR\fR
437 .sp .6
438 .RS 4n
439 This command stops an isochronous transfer. The argument is a handle returned
440 by \fBIEC61883_ISOCH_INIT\fR.
444 .ne 2
446 \fB\fBIEC61883_RECV\fR\fR
448 .sp .6
449 .RS 4n
450 This command is used to receive full frames and return empty frames to the
451 driver. The argument is a pointer to the structure:
453 .in +2
455 typedef struct iec61883_recv {
456         int rx_handle;     /* isoch handle */
457         int rx_flags;      /* flags */
458 iec61883_xfer_t rx_xfer;   /* xfer params */
459 } iec61883_recv_t;
461 typedef struct iec61883_xfer {
462         int   xf_empty_idx; /* first empty frame */
463         int xf_empty_cnt;   /* empty frame count */
464         int   xf_full_idx;  /* first full frame */
465         int   xf_full_cnt;  /* full frame count */
466         int   xf_error;     /* error */
467 } iec61883_xfer_t;
469 .in -2
472 \fBrx_flags\fR should be set to 0.
474 An application sets \fBxf_empty_idx\fR and \fBxf_empty_cnt\fR to indicate
475 frames it no longer needs. E.g. if a buffer consists of 6 frames,
476 \fBxf_empty_idx\fR is 4, \fBxf_empty_cnt\fR is 3 - means that frames 4, 5 and 0
477 can now be reused by the driver. If there are no empty frames, for example, the
478 first time this command is called, \fBxf_empty_cnt\fR should be set to 0.
480 When the command returns, \fBxf_full_idx\fR and \fBxf_full_cnt\fR specifies the
481 frames that are full. \fBxf_error\fR is always 0.
483 In general, AV frame boundaries are not aligned with the frame buffer
484 boundaries, because the first received packet might not be the first packet of
485 an AV frame, and, in contrast with the read/write method, the driver does not
486 remove empty CIP packets.
488 Applications should detect empty packets by comparing adjacent packets'
489 continuity counters (DBC field of the CIP header).
493 .ne 2
495 \fB\fBIEC61883_XMIT\fR\fR
497 .sp .6
498 .RS 4n
499 This command is used to transmit full frames and get more empty frames from the
500 driver. The argument is a pointer to the structure:
502 .in +2
504 typedef struct iec61883_xmit {
505         int   tx_handle;         /* isoch handle */
506         int   tx_flags;          /* flags */
507         iec61883_xfer_t tx_xfer; /* xfer params */
508         int   tx_miss_cnt;       /* missed cycles */
509  } iec61883_xmit_t;
511 .in -2
514 \fBtx_flags\fR should be set to zero.
516 The application sets \fBxf_full_idx\fR and \fBxf_full_cnt\fR to specify frames
517 it wishes to transmit. If there are no frames to transmit (e.g. the first time
518 this command is called), \fBxf_full_cnt\fR should be set to 0.
520 When the command returns, \fBxf_empty_idx\fR and \fBxf_empty_cnt\fR specifies
521 empty frames which can be to transmit more data. \fBxf_error\fR is always 0.
523 \fBtx_miss_cnt\fR contains the number of isochronous cycles missed since last
524 transfer due to data buffer under run. This can happen when an application does
525 not supply data fast enough.
527 For the purposes of time stamping, the driver considers the first packet in a
528 frame buffer to be the first packet of an AV frame.
532 .ne 2
534 \fB\fBIEC61883_PLUG_INIT\fR\fR
536 .sp .6
537 .RS 4n
538 This command returns a handle for the specified plug. The argument is a pointer
539 to the structure:
541 .in +2
543 typedef struct iec61883_plug_init {
544         int   pi_ver;     /* interface version */
545         int   pi_loc;     /* plug location */
546         int   pi_type;    /* plug type */
547         int   pi_num;     /* plug number */
548         int   pi_flags;   /* flags */
549         int   pi_handle;  /* plug handle */
550         int   pi_rnum;    /* plug number */
551  } iec61883_plug_init_t;
553 .in -2
556 \fBpi_ver\fR should be set to \fBIEC61883_V1_0\fR.
558 \fBpi_loc\fR specifies plug location:
560 .ne 2
562 \fB\fBIEC61883_LOC_LOCAL\fR\fR
564 .sp .6
565 .RS 4n
566 On the local unit (local plug). A plug control register (PCR) is allocated.
567 Command fails if the plug already exists
571 .ne 2
573 \fB\fBIEC61883_LOC_REMOTE\fR\fR
575 .sp .6
576 .RS 4n
577 On the remote unit (remote plug). The plug should exist on the remote unit,
578 otherwise the command fails.
581 \fBpi_type\fR specifies isochronous plug type:
583 .ne 2
585 \fB\fBIEC61883_PLUG_IN IEC61883_PLUG_OUT\fR\fR
587 .sp .6
588 .RS 4n
589 Input or output plugs.
593 .ne 2
595 \fB\fBIEC61883_PLUG_MASTER_IN IEC61883_PLUG_MASTER_OUT\fR\fR
597 .sp .6
598 .RS 4n
599 Master input or master output plug. These plugs always exist on the local unit.
602 \fBpi_num\fR specifies plug number. This should be 0 for master plugs, and from
603 0 to 31 for input/output plugs. Alternatively, a special value
604 \fBIEC61883_PLUG_ANY\fR can be used to let the driver choose a free plug
605 number, create the plug and return the number in \fBpi_rnum\fR.
607 \fBpi_flags\fR should be set to 0.
609 If the command succeeds, \fBpi_handle\fR contains a handle that should be used
610 with other plug commands.
614 .ne 2
616 \fB\fBIEC61883_PLUG_FINI\fR\fR
618 .sp .6
619 .RS 4n
620 Argument is a handle returned by \fBIEC61883_PLUG_INIT\fR. This command frees
621 any resources associated with this handle, including the PCR.
625 .ne 2
627 \fB\fBIEC61883_PLUG_REG_READ\fR\fR
629 .sp .6
630 .RS 4n
631 Read plug register value. The argument is a pointer to the structure:
633 .in +2
635 typedef struct iec61883_plug_reg_val {
636         int         pr_handle; /* plug handle */
637         uint32_t     pr_val;    /* register value */
638 } iec61883_plug_reg_val_t;
640 .in -2
643 \fBpr_handle\fR is a handle returned by \fBIEC61883_PLUG_INIT\fR. Register
644 value is returned in \fBpr_val\fR.
648 .ne 2
650 \fB\fBIEC61883_PLUG_REG_CAS\fR\fR
652 .sp .6
653 .RS 4n
654 Atomically compare and swap plug register value. The argument is a pointer to
655 the structure:
657 .in +2
659 typedef struct iec61883_plug_reg_lock {
660         int        pl_handle; /* plug handle */
661         uint32_t   pl_arg;    /* compare arg */
662         uint32_t   pl_data;   /* write value */
663         UINT32_t   pl_old;    /* original value */
664 } iec61883_plug_reg_lock_t;
666 .in -2
669 pr_handle is a handle returned by IEC61883_PLUG_INIT.
671 Original register value is compared with pl_arg and if they are equal, register
672 value is replaced with pl_data. In any case, the original value is stored in
673 pl_old.
678 The following commands only apply to asynchronous nodes:
680 .ne 2
682 \fB\fBIEC61883_ARQ_GET_IBUF_SIZE\fR\fR
684 .sp .6
685 .RS 4n
686 This command returns current incoming ARQ buffer size. The argument is a
687 pointer to \fBint\fR.
691 .ne 2
693 \fB\fBIEC61883_ARQ_SET_IBUF_SIZE\fR\fR
695 .sp .6
696 .RS 4n
697 This command changes incoming ARQ buffer size. The argument is the new buffer
698 size in bytes.
701 .SH FILES
703 .ne 2
705 \fB\fB/dev/av/N/async\fR\fR
707 .RS 19n
708 Device node for asynchronous data
712 .ne 2
714 \fB\fB/dev/av/N/isoch\fR\fR
716 .RS 19n
717 Device has been disconnected
720 .SH ERRORS
722 .ne 2
724 \fB\fBEIO\fR\fR
726 .RS 10n
727 Bus operation failed.
729 DMA failure.
733 .ne 2
735 \fB\fBEFAULT\fR\fR
737 .RS 10n
738 \fBioctl\fR(2) argument points to an illegal address.
742 .ne 2
744 \fB\fBEINVAL\fR\fR
746 .RS 10n
747 Invalid argument or argument combination.
751 .ne 2
753 \fB\fBENODEV\fR\fR
755 .RS 10n
756 Device has been disconnected.
759 .SH ATTRIBUTES
762 See \fBattributes\fR(5) for descriptions of the following attributes:
767 box;
768 c | c
769 l | l .
770 ATTRIBUTE TYPE  ATTRIBUTE VALUE
772 Architecture    All
774 Stability level Committed
777 .SH SEE ALSO
780 \fBioctl\fR(2), \fBmmap\fR(2), \fBopen\fR(2), \fBpoll\fR(2), \fBread\fR(2),
781 \fBwrite\fR(2), \fBattributes\fR(5), \fBav1394\fR(7D)
784 \fIIEC 61883 Consumer audio/video equipment - Digital interface\fR
787 \fIIEEE Std 1394-1995 Standard for a High Performance Serial Bus\fR