SMBIOS Library
CmosRW_LinuxIO.cpp
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0:
3  *
4  * Copyright (C) 2005 Dell Inc.
5  * by Michael Brown <Michael_E_Brown@dell.com>
6  * Licensed under the Open Software License version 2.1
7  *
8  * Alternatively, you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published
10  * by the Free Software Foundation; either version 2 of the License,
11  * or (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  */
18 
19 // compat header should always be first header if including system headers
20 #define LIBSMBIOS_SOURCE
21 #include "smbios/compat.h"
22 
23 #include <sys/io.h>
24 
25 #include "CmosRWImpl.h"
26 
27 using namespace std;
28 
29 namespace cmos
30 {
31 
32  //
33  // CmosRWIo functions
34  //
35 
36  // REGULAR CONSTRUCTOR
37  CmosRWIo::CmosRWIo ()
38  : ICmosRW(), Suppressable()
39  {}
40 
41  // COPY CONSTRUCTOR
43  : ICmosRW(), Suppressable()
44  {}
45 
46  // OVERLOADED ASSIGNMENT
48  {
49  return *this;
50  }
51 
52  // TODO: need to throw exception on problem with iopl
53  //
54  u8 CmosRWIo::readByte (u32 indexPort, u32 dataPort, u32 offset) const
55  {
56  if(iopl(3) < 0)
57  throw smbios::InternalErrorImpl("iopl() failed. probably not root.");
58  outb_p (offset, indexPort);
59  return (inb_p (dataPort));
60  }
61 
62  // TODO: need to throw exception on problem with iopl
63  //
64  void CmosRWIo::writeByte (u32 indexPort, u32 dataPort, u32 offset, u8 byte) const
65  {
66  if(iopl(3) < 0)
67  throw smbios::InternalErrorImpl("iopl() failed. probably not root.");
68  outb_p (offset, indexPort);
69  outb_p (byte, dataPort);
70 
71  if(! isNotifySuppressed() )
72  {
73  // writers are responsible for only writing changed values
74  // otherwise we get to see how fast Linux can do an
75  // infinite loop. :-)
76  notify();
77  }
78  }
79 
80 }