The Pedigree Project  0.1
modules/drivers/ppc/ata-specific/main.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 "modules/Module.h"
21 #include "pedigree/kernel/Log.h"
22 #include "pedigree/kernel/machine/Device.h"
23 #include "pedigree/kernel/machine/openfirmware/Device.h"
24 #include "pedigree/kernel/processor/Processor.h"
25 #include "pedigree/kernel/processor/types.h"
26 
27 static void searchNode(Device *pDev)
28 {
29  for (unsigned int i = 0; i < pDev->getNumChildren(); i++)
30  {
31  Device *pChild = pDev->getChild(i);
32 
34  if (pChild->getSpecificType() == "pci-ide")
35  {
36  // We've found a native-pci ATA device.
37 
38  // BAR0 is the command register address, BAR1 is the control
39  // register address.
40  for (int j = 0; j < pChild->addresses().count(); j++)
41  {
42  if (pChild->addresses()[j]->m_Name == "bar0")
43  pChild->addresses()[j]->m_Name = String("command");
44  if (pChild->addresses()[j]->m_Name == "bar1")
45  pChild->addresses()[j]->m_Name = String("control");
46  }
47  }
48 
49  if (pChild->getSpecificType() == "ata")
50  {
51  OFDevice dev(pChild->getOFHandle());
52  NormalStaticString compatible;
53  dev.getProperty("compatible", compatible);
54 
55  if (compatible == "keylargo-ata")
56  {
57  // iBook's keylargo controller.
58 
59  // The reg property gives in the first 32-bits the offset into
60  // the parent's BAR0 (mac-io) of all our registers.
61  uintptr_t reg;
62  dev.getProperty("reg", &reg, 4);
63 
64  for (unsigned int j = 0;
65  j < pChild->getParent()->addresses().count(); j++)
66  {
67  if (pChild->getParent()->addresses()[j]->m_Name == "bar0")
68  {
69  reg += pChild->getParent()->addresses()[j]->m_Address;
70  break;
71  }
72  }
73 
74  pChild->addresses().pushBack(new Device::Address(
75  String("command"), reg, 0x160, false, /* Not IO */
76  0x10)); /* Padding of 16 */
77  pChild->addresses().pushBack(new Device::Address(
78  String("control"), reg + 0x160, /* From linux source. */
79  0x100, false, /* Not IO */
80  0x10)); /* Padding of 16 */
81  }
82  }
83 
84  // Recurse.
85  searchNode(pChild);
86  }
87 }
88 
89 bool entry()
90 {
91  Device *pDev = &Device::root();
92  searchNode(pDev);
93 
95  return true;
96 }
97 
98 void exit()
99 {
100 }
101 
102 MODULE_NAME("ata-specific");
103 MODULE_ENTRY(&entry);
104 MODULE_EXIT(&exit);
105 MODULE_DEPENDS(0);
Device * getChild(size_t n)
Definition: Device.cc:132
size_t getNumChildren()
Definition: Device.cc:137
virtual String getSpecificType()
Definition: Device.h:169
virtual Vector< Address * > & addresses()
Definition: Device.h:256
Definition: String.h:49
Definition: Device.h:43
static Device & root()
Definition: Device.h:356
Device * getParent() const
Definition: Device.h:149