MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / Init

Function Init

Kernel/src/storage/ata.cpp:99–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97 }
98
99 int Init(){
100 if(!PCI::FindGenericDevice(ideClassCode, ideSubclass)){
101 Log::Warning("[ATA] No IDE controller found!");
102 return 1;
103 }
104
105 controllerPCIDevice = &PCI::GetGenericPCIDevice(ideClassCode, ideSubclass);
106 assert(controllerPCIDevice->vendorID != 0xFFFF);
107
108 Log::Info("[ATA] Initializing...");
109
110 if(controllerPCIDevice->BarIsIOPort(0)){
111 uintptr_t bar;
112 if((bar = controllerPCIDevice->GetBaseAddressRegister(0))){
113 port0 = bar;
114 }
115 }
116
117 if(controllerPCIDevice->BarIsIOPort(1)){
118 uintptr_t bar;
119 if((bar = controllerPCIDevice->GetBaseAddressRegister(1))){
120 port1 = bar;
121 }
122 }
123
124 if(controllerPCIDevice->BarIsIOPort(2)){
125 uintptr_t bar;
126 if((bar = controllerPCIDevice->GetBaseAddressRegister(2))){
127 controlPort0 = bar;
128 }
129 }
130
131 if(controllerPCIDevice->BarIsIOPort(3)){
132 uintptr_t bar;
133 if((bar = controllerPCIDevice->GetBaseAddressRegister(3))){
134 controlPort1 = bar;
135 }
136 }
137
138 assert(controllerPCIDevice->BarIsIOPort(4));
139 busMasterPort = controllerPCIDevice->GetBaseAddressRegister(4);
140 controllerPCIDevice->EnableBusMastering();
141
142 if(debugLevelATA >= DebugLevelNormal){
143 Log::Info("[ATA] Using Ports: Primary %x, Secondary %x", port0, port1);
144 }
145
146 for(int i = 0; i < 2; i++){ // Port
147 WriteControlRegister(i, 0, ReadControlRegister(i, 0) | 4); // Software Reset
148
149 for(int z = 0; z < 4; z++) inportb(controlPort0);
150
151 WriteControlRegister(i, 0, 0);
152
153 for(int j = 0; j < 2; j++){ // Drive (master/slave)
154 if(DetectDrive(i, j)){
155 if(debugLevelATA >= DebugLevelNormal){
156 Log::Info("Found ATA Drive: Port: %d, %s", i, j ? "slave" : "master");

Callers 2

KernelProcessFunction · 0.50
kmainFunction · 0.50

Calls 12

FindGenericDeviceFunction · 0.85
WarningFunction · 0.85
InfoFunction · 0.85
WriteControlRegisterFunction · 0.85
ReadControlRegisterFunction · 0.85
inportbFunction · 0.85
DetectDriveFunction · 0.85
inportwFunction · 0.85
RegisterDeviceFunction · 0.85
BarIsIOPortMethod · 0.80
EnableBusMasteringMethod · 0.80

Tested by

no test coverage detected