The Pedigree Project  0.1
openfirmware/Device.cc
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "pedigree/kernel/machine/openfirmware/Device.h"
21 #include "pedigree/kernel/Log.h"
22 #include "pedigree/kernel/machine/openfirmware/OpenFirmware.h"
23 
24 OFDevice::OFDevice(OFHandle handle) : m_Handle(handle)
25 {
26 }
27 
28 OFDevice::~OFDevice()
29 {
30 }
31 
32 void OFDevice::getProperty(const char *pProperty, NormalStaticString &buf)
33 {
34  char buf2[64];
35  OFParam ret = OpenFirmware::instance().call(
36  "instance-to-package", 1, static_cast<OFParam>(m_Handle));
37  if (reinterpret_cast<int>(ret) == -1)
38  ret = static_cast<OFParam>(m_Handle);
40  "getprop", 4, ret,
41  reinterpret_cast<OFParam>(const_cast<char *>(pProperty)),
42  static_cast<OFParam>(buf2), reinterpret_cast<OFParam>(64));
43  buf += buf2;
44 }
45 
46 OFHandle OFDevice::getProperty(const char *pProperty)
47 {
48  OFHandle h;
49  OFParam ret = OpenFirmware::instance().call(
50  "instance-to-package", 1, static_cast<OFParam>(m_Handle));
51  if (reinterpret_cast<int>(ret) == -1)
52  ret = static_cast<OFParam>(m_Handle);
54  "getprop", 4, ret,
55  reinterpret_cast<OFParam>(const_cast<char *>(pProperty)),
56  reinterpret_cast<OFParam>(&h),
57  reinterpret_cast<OFParam>(sizeof(OFHandle)));
58  return h;
59 }
60 
61 int OFDevice::getProperty(const char *pProperty, void *buf, size_t bufLen)
62 {
63  OFParam ret = OpenFirmware::instance().call(
64  "instance-to-package", 1, static_cast<OFParam>(m_Handle));
65  if (reinterpret_cast<int>(ret) == -1)
66  ret = static_cast<OFParam>(m_Handle);
67  return reinterpret_cast<int>(OpenFirmware::instance().call(
68  "getprop", 4, ret,
69  reinterpret_cast<OFParam>(const_cast<char *>(pProperty)),
70  reinterpret_cast<OFParam>(buf), reinterpret_cast<OFParam>(bufLen)));
71 }
72 
73 bool OFDevice::propertyExists(const char *pProperty)
74 {
75  OFHandle h;
76  OFParam ret = OpenFirmware::instance().call(
77  "instance-to-package", 1, static_cast<OFParam>(m_Handle));
78  if (reinterpret_cast<int>(ret) == -1)
79  ret = static_cast<OFParam>(m_Handle);
81  "getprop", 4, ret,
82  reinterpret_cast<OFParam>(const_cast<char *>(pProperty)),
83  reinterpret_cast<OFParam>(&h),
84  reinterpret_cast<OFParam>(sizeof(OFHandle))) !=
85  reinterpret_cast<OFHandle>(-1);
86 }
87 
88 OFHandle OFDevice::getParent()
89 {
90  OFParam ret = OpenFirmware::instance().call(
91  "instance-to-package", 1, static_cast<OFParam>(m_Handle));
92  if (reinterpret_cast<int>(ret) == -1)
93  ret = static_cast<OFParam>(m_Handle);
94  return static_cast<OFHandle>(OpenFirmware::instance().call(
95  "parent", 1, reinterpret_cast<OFParam>(ret)));
96 }
97 
98 int OFDevice::getPropertyLength(const char *pProperty)
99 {
100  OFParam ret = OpenFirmware::instance().call(
101  "instance-to-package", 1, static_cast<OFParam>(m_Handle));
102  if (reinterpret_cast<int>(ret) == -1)
103  ret = static_cast<OFParam>(m_Handle);
104  return reinterpret_cast<int>(OpenFirmware::instance().call(
105  "getproplen", 2, ret,
106  reinterpret_cast<OFParam>(const_cast<char *>(pProperty))));
107 }
108 
109 int OFDevice::getNextProperty(const char *pPrevious, const char *pNext)
110 {
111  // Requires a phandle.
112  OFParam ret = OpenFirmware::instance().call(
113  "instance-to-package", 1, static_cast<OFParam>(m_Handle));
114  if (reinterpret_cast<int>(ret) == -1)
115  ret = static_cast<OFParam>(m_Handle);
116  return reinterpret_cast<int>(OpenFirmware::instance().call(
117  "nextprop", 3, ret,
118  reinterpret_cast<OFParam>(const_cast<char *>(pPrevious)),
119  reinterpret_cast<OFParam>(const_cast<char *>(pNext))));
120 }
121 
122 void OFDevice::setProperty(const char *pProperty, NormalStaticString &val)
123 {
125 }
126 
127 OFHandle OFDevice::executeMethod(
128  const char *method, size_t nArgs, OFParam p1, OFParam p2, OFParam p3,
129  OFParam p4, OFParam p5, OFParam p6)
130 {
131  return OpenFirmware::instance().call(
132  "call-method", nArgs + 2,
133  reinterpret_cast<OFParam>(const_cast<char *>(method)),
134  static_cast<OFParam>(m_Handle), p1, p2, p3, p4, p5, p6);
135 }
static OpenFirmware & instance()
Definition: OpenFirmware.h:45
OFParam call(const char *pService, int nArgs, OFParam p1=0, OFParam p2=0, OFParam p3=0, OFParam p4=0, OFParam p5=0, OFParam p6=0, OFParam p7=0, OFParam p8=0)
Definition: OpenFirmware.cc:64
virtual void setProperty(const char *pProperty, NormalStaticString &val)