1 // Copyright 2016 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <zircon/compiler.h>
8 #include <zircon/device/ioctl.h>
9 #include <zircon/types.h>
10 
11 #define IHDA_IOCTL_GET_CHANNEL IOCTL(IOCTL_KIND_GET_HANDLE, 0xFF, 0x00)
12 
13 // When communicating with an IHDA driver using zx_channel_call, do not use the
14 // IHDA_INVALID_TRANSACTION_ID as your message's transaction ID.
15 #define IHDA_INVALID_TRANSACTION_ID ((zx_txid_t)0)
16 
17 // Invalid Stream ID and Stream TAG.  These values will never be returned as
18 // part of a successful REQUEST_STREAM response.
19 #define IHDA_INVALID_STREAM_ID  ((uint16_t)0)
20 #define IHDA_INVALID_STREAM_TAG ((uint8_t)0)
21 
22 // Size of a register snapshot
23 #define IHDA_REGISTER_SNAPSHOT_SIZE (8u << 10)
24 
25 __BEGIN_CDECLS
26 
27 typedef uint32_t ihda_cmd_t;
28 #define IHDA_CMD_GET_IDS                  ((ihda_cmd_t)0x1000)
29 #define IHDA_CONTROLLER_CMD_SNAPSHOT_REGS ((ihda_cmd_t)0x2000)
30 #define IHDA_CODEC_SEND_CORB_CMD          ((ihda_cmd_t)0x3000)
31 #define IHDA_CODEC_REQUEST_STREAM         ((ihda_cmd_t)0x3001)
32 #define IHDA_CODEC_RELEASE_STREAM         ((ihda_cmd_t)0x3002)
33 #define IHDA_CODEC_SET_STREAM_FORMAT      ((ihda_cmd_t)0x3003)
34 #define IHDA_NOACK_FLAG                   ((ihda_cmd_t)0x80000000)
35 #define IHDA_CODEC_SEND_CORB_CMD_NOACK    ((ihda_cmd_t)(IHDA_NOACK_FLAG | IHDA_CODEC_SEND_CORB_CMD))
36 #define IHDA_CODEC_RELEASE_STREAM_NOACK   ((ihda_cmd_t)(IHDA_NOACK_FLAG | IHDA_CODEC_RELEASE_STREAM))
37 
38 typedef struct ihda_cmd_hdr {
39     zx_txid_t  transaction_id;
40     ihda_cmd_t cmd;
41 } ihda_cmd_hdr_t;
42 
43 // IHDA_CONTROLLER_CMD_GET_IDS
44 typedef struct ihda_get_ids_req {
45     ihda_cmd_hdr_t hdr;
46 } ihda_get_ids_req_t;
47 
48 typedef struct ihda_get_ids_resp {
49     ihda_cmd_hdr_t  hdr;
50     uint16_t        vid;
51     uint16_t        did;
52     uint8_t         ihda_vmaj;
53     uint8_t         ihda_vmin;
54     uint8_t         rev_id;
55     uint8_t         step_id;
56 } ihda_get_ids_resp_t;
57 
58 // IHDA_CONTROLLER_CMD_SNAPSHOT_REGS,
59 //
60 // Note: returns a snapshot of just the primary register file.  Alias registers
61 // are not included.
62 //
63 // TODO(johngro): When we have a way to return a handle to a read-only VMO which
64 // provides access to the actual PCI registers, do that instead of snapshotting
65 // and marshaling the result back.
66 typedef struct ihda_controller_snapshot_regs_req {
67     ihda_cmd_hdr_t hdr;
68 } ihda_controller_snapshot_regs_req_t;
69 
70 typedef struct ihda_controller_snapshot_regs_resp {
71     ihda_cmd_hdr_t  hdr;
72     uint8_t         snapshot[IHDA_REGISTER_SNAPSHOT_SIZE];
73 } ihda_controller_snapshot_regs_resp_t;
74 
75 // IHDA_CODEC_SEND_CORB_CMD
76 //
77 // TODO(johngro) : minimize thread context switching by allowing more than one
78 // command to be queued per job.
79 //
80 typedef struct ihda_codec_send_corb_cmd_req {
81     ihda_cmd_hdr_t hdr;
82     uint32_t       verb;
83     uint16_t       nid;
84 } ihda_codec_send_corb_cmd_req_t;
85 
86 typedef struct ihda_codec_send_corb_cmd_resp {
87     ihda_cmd_hdr_t  hdr;
88     uint32_t        data;
89     uint32_t        data_ex;
90 } ihda_codec_send_corb_cmd_resp_t;
91 
92 // IHDA_CODEC_REQUEST_STREAM
93 //
94 typedef struct ihda_codec_request_stream_req {
95     ihda_cmd_hdr_t  hdr;
96     bool            input;          // true => input, false => output
97 } ihda_codec_request_stream_req_t;
98 
99 typedef struct ihda_codec_request_stream_resp {
100     ihda_cmd_hdr_t  hdr;
101     zx_status_t     result;
102     uint16_t        stream_id;
103     uint8_t         stream_tag;
104 } ihda_codec_request_stream_resp_t;
105 
106 // IHDA_CODEC_RELEASE_STREAM
107 //
108 typedef struct ihda_codec_release_stream_req {
109     ihda_cmd_hdr_t  hdr;
110     uint16_t        stream_id;
111 } ihda_codec_release_stream_req_t;
112 
113 typedef struct ihda_codec_release_stream_resp {
114     ihda_cmd_hdr_t  hdr;
115 } ihda_codec_release_stream_resp_t;
116 
117 // IHDA_CODEC_SET_STREAM_FORMAT
118 //
119 typedef struct ihda_codec_set_stream_format_req {
120     ihda_cmd_hdr_t  hdr;
121     uint16_t        stream_id;
122     uint16_t        format;         // see section 3.7.1
123 } ihda_codec_set_stream_format_req_t;
124 
125 typedef struct ihda_codec_set_stream_format_resp {
126     ihda_cmd_hdr_t  hdr;
127 } ihda_codec_set_stream_format_resp_t;
128 
129 __END_CDECLS
130