vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / accelerants / common / dp.cpp
blob533ecca0b27211bda52ec77273cf87eca9629f6b
1 /*
2 * Copyright 2012-2016, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Alexander von Gluck, kallisti5@unixzen.com
7 */
10 #include "dp.h"
13 #define TRACE_DISPLAY
14 #ifdef TRACE_DISPLAY
15 extern "C" void _sPrintf(const char* format, ...);
16 # define TRACE(x...) _sPrintf("dp_common: " x)
17 #else
18 # define TRACE(x...) ;
19 #endif
21 #define ERROR(x...) _sPrintf("dp_common: " x)
24 uint32
25 dp_encode_link_rate(uint32 linkRate)
27 switch (linkRate) {
28 case 162000:
29 // 1.62 Ghz
30 return DP_LINK_RATE_162;
31 case 270000:
32 // 2.7 Ghz
33 return DP_LINK_RATE_270;
34 case 540000:
35 // 5.4 Ghz
36 return DP_LINK_RATE_540;
39 ERROR("%s: Unknown DisplayPort Link Rate! (0x%" B_PRIX32 ")\n",
40 __func__, linkRate);
41 return DP_LINK_RATE_162;
45 uint32
46 dp_decode_link_rate(uint32 rawLinkRate)
48 switch (rawLinkRate) {
49 case DP_LINK_RATE_162:
50 return 162000;
51 case DP_LINK_RATE_270:
52 return 270000;
53 case DP_LINK_RATE_540:
54 return 540000;
56 ERROR("%s: Unknown DisplayPort Link Rate! (0x%" B_PRIX32 ")\n",
57 __func__, rawLinkRate);
58 return 162000;
62 uint32
63 dp_get_pixel_clock_max(int linkRate, int laneCount, int bpp)
65 return (linkRate * laneCount * 8) / bpp;