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