vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / accelerants / s3 / virge_dpms.cpp
blobec5b89c16a7aa14ba47c11669b23abf05fb56a2c
1 /*
2 Haiku S3 Virge driver adapted from the X.org Virge driver.
4 Copyright (C) 1994-1999 The XFree86 Project, Inc. All Rights Reserved.
6 Copyright 2007-2008 Haiku, Inc. All rights reserved.
7 Distributed under the terms of the MIT license.
9 Authors:
10 Gerald Zajac 2007-2008
14 #include "accel.h"
15 #include "virge.h"
19 uint32
20 Virge_DPMSCapabilities(void)
22 // Return DPMS modes supported by this device.
24 return B_DPMS_ON | B_DPMS_STAND_BY | B_DPMS_SUSPEND | B_DPMS_OFF;
28 uint32
29 Virge_GetDPMSMode(void)
31 // Return the current DPMS mode.
33 // Note: I do not know whether the following code is correctly reading
34 // the current DPMS mode. I'm assuming that reading back the bits that
35 // were set by function Virge_SetDPMSMode will give the current DPMS mode.
37 uint32 mode = B_DPMS_ON;
39 switch (ReadSeqReg(0x0d) & 0x70) {
40 case 0:
41 mode = B_DPMS_ON;
42 break;
43 case 0x10:
44 mode = B_DPMS_STAND_BY;
45 break;
46 case 0x40:
47 mode = B_DPMS_SUSPEND;
48 break;
49 case 0x50:
50 mode = B_DPMS_OFF;
51 break;
52 default:
53 TRACE("Unknown DPMS mode, reg sr0D: 0x%X\n", ReadSeqReg(0x0d));
56 TRACE("Virge_GetDPMSMode() mode: %d\n", mode);
57 return mode;
61 status_t
62 Virge_SetDPMSMode(uint32 dpmsMode)
64 // Set the display into one of the Display Power Management modes,
65 // and return B_OK if successful, else return B_ERROR.
67 TRACE("Virge_SetDPMSMode() mode: %d\n", dpmsMode);
69 WriteSeqReg(0x08, 0x06); // unlock extended sequencer regs
71 uint8 sr0D = ReadSeqReg(0x0d) & 0x03;
73 switch (dpmsMode) {
74 case B_DPMS_ON:
75 break;
76 case B_DPMS_STAND_BY:
77 sr0D |= 0x10;
78 break;
79 case B_DPMS_SUSPEND:
80 sr0D |= 0x40;
81 break;
82 case B_DPMS_OFF:
83 sr0D |= 0x50;
84 break;
85 default:
86 TRACE("Invalid DPMS mode %d\n", dpmsMode);
87 return B_ERROR;
90 WriteSeqReg(0x0d, sr0D);
92 return B_OK;