xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/disp/nouveau_nvkm_engine_disp_hdmi.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: nouveau_nvkm_engine_disp_hdmi.c,v 1.2 2021/12/18 23:45:35 riastradh Exp $	*/
2 
3 // SPDX-License-Identifier: MIT
4 #include <sys/cdefs.h>
5 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_disp_hdmi.c,v 1.2 2021/12/18 23:45:35 riastradh Exp $");
6 
7 #include "hdmi.h"
8 
pack_hdmi_infoframe(struct packed_hdmi_infoframe * packed_frame,u8 * raw_frame,ssize_t len)9 void pack_hdmi_infoframe(struct packed_hdmi_infoframe *packed_frame,
10 			 u8 *raw_frame, ssize_t len)
11 {
12 	u32 header = 0;
13 	u32 subpack0_low = 0;
14 	u32 subpack0_high = 0;
15 	u32 subpack1_low = 0;
16 	u32 subpack1_high = 0;
17 
18 	switch (len) {
19 		/*
20 		 * "When in doubt, use brute force."
21 		 *     -- Ken Thompson.
22 		 */
23 	default:
24 		/*
25 		 * We presume that no valid frame is longer than 17
26 		 * octets, including header...  And truncate to that
27 		 * if it's longer.
28 		 */
29 	case 17:
30 		subpack1_high = (raw_frame[16] << 16);
31 		/* fall through */
32 	case 16:
33 		subpack1_high |= (raw_frame[15] << 8);
34 		/* fall through */
35 	case 15:
36 		subpack1_high |= raw_frame[14];
37 		/* fall through */
38 	case 14:
39 		subpack1_low = (raw_frame[13] << 24);
40 		/* fall through */
41 	case 13:
42 		subpack1_low |= (raw_frame[12] << 16);
43 		/* fall through */
44 	case 12:
45 		subpack1_low |= (raw_frame[11] << 8);
46 		/* fall through */
47 	case 11:
48 		subpack1_low |= raw_frame[10];
49 		/* fall through */
50 	case 10:
51 		subpack0_high = (raw_frame[9] << 16);
52 		/* fall through */
53 	case 9:
54 		subpack0_high |= (raw_frame[8] << 8);
55 		/* fall through */
56 	case 8:
57 		subpack0_high |= raw_frame[7];
58 		/* fall through */
59 	case 7:
60 		subpack0_low = (raw_frame[6] << 24);
61 		/* fall through */
62 	case 6:
63 		subpack0_low |= (raw_frame[5] << 16);
64 		/* fall through */
65 	case 5:
66 		subpack0_low |= (raw_frame[4] << 8);
67 		/* fall through */
68 	case 4:
69 		subpack0_low |= raw_frame[3];
70 		/* fall through */
71 	case 3:
72 		header = (raw_frame[2] << 16);
73 		/* fall through */
74 	case 2:
75 		header |= (raw_frame[1] << 8);
76 		/* fall through */
77 	case 1:
78 		header |= raw_frame[0];
79 		/* fall through */
80 	case 0:
81 		break;
82 	}
83 
84 	packed_frame->header = header;
85 	packed_frame->subpack0_low = subpack0_low;
86 	packed_frame->subpack0_high = subpack0_high;
87 	packed_frame->subpack1_low = subpack1_low;
88 	packed_frame->subpack1_high = subpack1_high;
89 }
90