mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-29 07:47:59 +00:00
Organize driver binding files
This commit is contained in:
parent
411b468f71
commit
37f5b77421
@ -31,70 +31,6 @@
|
|||||||
|
|
||||||
namespace Driver
|
namespace Driver
|
||||||
{
|
{
|
||||||
DriverCode Driver::BindInputGeneric(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindInputDisplay(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindInputNetwork(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindInputStorage(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindInputFileSystem(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindInputInput(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
KernelCallback *KCallback = (KernelCallback *)mem->RequestPages(TO_PAGES(sizeof(KernelCallback) + 1));
|
|
||||||
|
|
||||||
fixme("Input driver: %s", fexExtended->Driver.Name);
|
|
||||||
KCallback->RawPtr = nullptr;
|
|
||||||
KCallback->Reason = CallbackReason::ConfigurationReason;
|
|
||||||
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(KCallback);
|
|
||||||
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
|
||||||
{
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
error("Driver %s is not implemented", fexExtended->Driver.Name);
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
else if (CallbackRet != DriverReturnCode::OK)
|
|
||||||
{
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
error("Driver %s returned error %d", fexExtended->Driver.Name, CallbackRet);
|
|
||||||
return DriverCode::DRIVER_RETURNED_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
fixme("Input driver: %s", fexExtended->Driver.Name);
|
|
||||||
|
|
||||||
DriverFile DrvFile = {
|
|
||||||
.Enabled = true,
|
|
||||||
.DriverUID = this->DriverUIDs - 1,
|
|
||||||
.Address = (void *)fex,
|
|
||||||
.MemTrk = mem,
|
|
||||||
};
|
|
||||||
Drivers.push_back(DrvFile);
|
|
||||||
return DriverCode::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindInputAudio(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::DriverLoadBindInput(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf)
|
DriverCode Driver::DriverLoadBindInput(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf)
|
||||||
{
|
{
|
||||||
UNUSED(DrvExtHdr);
|
UNUSED(DrvExtHdr);
|
84
Core/Driver/DriverBinding/BindInterrupt.cpp
Normal file
84
Core/Driver/DriverBinding/BindInterrupt.cpp
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../kernel.h"
|
||||||
|
#include "../../../DAPI.hpp"
|
||||||
|
#include "../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::DriverLoadBindInterrupt(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf)
|
||||||
|
{
|
||||||
|
UNUSED(IsElf);
|
||||||
|
Memory::MemMgr *mem = new Memory::MemMgr(nullptr, TaskManager->GetCurrentProcess()->memDirectory);
|
||||||
|
Fex *fex = (Fex *)mem->RequestPages(TO_PAGES(Size + 1));
|
||||||
|
memcpy(fex, (void *)DriverAddress, Size);
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
debug("Driver allocated at %#lx-%#lx", fex, (uintptr_t)fex + Size);
|
||||||
|
#ifdef DEBUG
|
||||||
|
uint8_t *result = md5File((uint8_t *)fex, Size);
|
||||||
|
debug("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||||
|
result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7],
|
||||||
|
result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15]);
|
||||||
|
kfree(result);
|
||||||
|
#endif
|
||||||
|
KernelAPI *KAPI = (KernelAPI *)mem->RequestPages(TO_PAGES(sizeof(KernelAPI) + 1));
|
||||||
|
|
||||||
|
if (CallDriverEntryPoint(fex, KAPI) != DriverCode::OK)
|
||||||
|
{
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::DRIVER_RETURNED_ERROR;
|
||||||
|
}
|
||||||
|
debug("Starting driver %s (offset: %#lx)", fexExtended->Driver.Name, fex);
|
||||||
|
|
||||||
|
switch (fexExtended->Driver.Type)
|
||||||
|
{
|
||||||
|
case FexDriverType::FexDriverType_Generic:
|
||||||
|
return BindInterruptGeneric(mem, fex);
|
||||||
|
case FexDriverType::FexDriverType_Display:
|
||||||
|
return BindInterruptDisplay(mem, fex);
|
||||||
|
case FexDriverType::FexDriverType_Network:
|
||||||
|
return BindInterruptNetwork(mem, fex);
|
||||||
|
case FexDriverType::FexDriverType_Storage:
|
||||||
|
return BindInterruptStorage(mem, fex);
|
||||||
|
case FexDriverType::FexDriverType_FileSystem:
|
||||||
|
return BindInterruptFileSystem(mem, fex);
|
||||||
|
case FexDriverType::FexDriverType_Input:
|
||||||
|
return BindInterruptInput(mem, fex);
|
||||||
|
case FexDriverType::FexDriverType_Audio:
|
||||||
|
return BindInterruptAudio(mem, fex);
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
warn("Unknown driver type: %d", fexExtended->Driver.Type);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::UNKNOWN_DRIVER_TYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return DriverCode::OK;
|
||||||
|
}
|
||||||
|
}
|
206
Core/Driver/DriverBinding/BindPCI.cpp
Normal file
206
Core/Driver/DriverBinding/BindPCI.cpp
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../kernel.h"
|
||||||
|
#include "../../../DAPI.hpp"
|
||||||
|
#include "../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
void Driver::MapPCIAddresses(PCI::PCIDeviceHeader *PCIDevice)
|
||||||
|
{
|
||||||
|
debug("Header Type: %d", PCIDevice->HeaderType);
|
||||||
|
switch (PCIDevice->HeaderType)
|
||||||
|
{
|
||||||
|
case 0: // PCI Header 0
|
||||||
|
{
|
||||||
|
uint32_t BAR[6] = {0};
|
||||||
|
size_t BARsSize[6] = {0};
|
||||||
|
|
||||||
|
BAR[0] = ((PCI::PCIHeader0 *)PCIDevice)->BAR0;
|
||||||
|
BAR[1] = ((PCI::PCIHeader0 *)PCIDevice)->BAR1;
|
||||||
|
BAR[2] = ((PCI::PCIHeader0 *)PCIDevice)->BAR2;
|
||||||
|
BAR[3] = ((PCI::PCIHeader0 *)PCIDevice)->BAR3;
|
||||||
|
BAR[4] = ((PCI::PCIHeader0 *)PCIDevice)->BAR4;
|
||||||
|
BAR[5] = ((PCI::PCIHeader0 *)PCIDevice)->BAR5;
|
||||||
|
|
||||||
|
uintptr_t BAR_Type = BAR[0] & 1;
|
||||||
|
uintptr_t BAR_IOBase = BAR[1] & (~3);
|
||||||
|
uintptr_t BAR_MemoryBase = BAR[0] & (~15);
|
||||||
|
|
||||||
|
debug("Type: %d; IOBase: %#lx; MemoryBase: %#lx", BAR_Type, BAR_IOBase, BAR_MemoryBase);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
if (BAR[i] == 0)
|
||||||
|
continue;
|
||||||
|
debug("BAR%d: %#lx", i, BAR[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* BARs Size */
|
||||||
|
for (size_t i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
if (BAR[i] == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ((BAR[i] & 1) == 0) // Memory Base
|
||||||
|
{
|
||||||
|
((PCI::PCIHeader0 *)PCIDevice)->BAR0 = 0xFFFFFFFF;
|
||||||
|
size_t size = ((PCI::PCIHeader0 *)PCIDevice)->BAR0;
|
||||||
|
((PCI::PCIHeader0 *)PCIDevice)->BAR0 = BAR[i];
|
||||||
|
BARsSize[i] = size & (~15);
|
||||||
|
BARsSize[i] = ~BARsSize[i] + 1;
|
||||||
|
BARsSize[i] = BARsSize[i] & 0xFFFFFFFF;
|
||||||
|
debug("BAR%dSize: %#lx", i, BARsSize[i]);
|
||||||
|
}
|
||||||
|
else if ((BAR[i] & 1) == 1) // I/O Base
|
||||||
|
{
|
||||||
|
((PCI::PCIHeader0 *)PCIDevice)->BAR1 = 0xFFFFFFFF;
|
||||||
|
size_t size = ((PCI::PCIHeader0 *)PCIDevice)->BAR1;
|
||||||
|
((PCI::PCIHeader0 *)PCIDevice)->BAR1 = BAR[i];
|
||||||
|
BARsSize[i] = size & (~3);
|
||||||
|
BARsSize[i] = ~BARsSize[i] + 1;
|
||||||
|
BARsSize[i] = BARsSize[i] & 0xFFFF;
|
||||||
|
debug("BAR%dSize: %#lx", i, BARsSize[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mapping the BARs */
|
||||||
|
for (size_t i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
if (BAR[i] == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ((BAR[i] & 1) == 0) // Memory Base
|
||||||
|
{
|
||||||
|
uintptr_t BARBase = BAR[i] & (~15);
|
||||||
|
size_t BARSize = BARsSize[i];
|
||||||
|
|
||||||
|
debug("Mapping BAR%d from %#lx to %#lx", i, BARBase, BARBase + BARSize);
|
||||||
|
Memory::Virtual().Map((void *)BARBase, (void *)BARBase, BARSize, Memory::PTFlag::RW | Memory::PTFlag::PWT);
|
||||||
|
}
|
||||||
|
else if ((BAR[i] & 1) == 1) // I/O Base
|
||||||
|
{
|
||||||
|
uintptr_t BARBase = BAR[i] & (~3);
|
||||||
|
uintptr_t BARSize = BARsSize[i];
|
||||||
|
|
||||||
|
debug("Mapping BAR%d from %#x to %#x", i, BARBase, BARBase + BARSize);
|
||||||
|
Memory::Virtual().Map((void *)BARBase, (void *)BARBase, BARSize, Memory::PTFlag::RW | Memory::PTFlag::PWT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1: // PCI Header 1 (PCI-to-PCI Bridge)
|
||||||
|
{
|
||||||
|
fixme("PCI Header 1 (PCI-to-PCI Bridge) not implemented yet");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2: // PCI Header 2 (PCI-to-CardBus Bridge)
|
||||||
|
{
|
||||||
|
fixme("PCI Header 2 (PCI-to-CardBus Bridge) not implemented yet");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
error("Unknown header type %d", PCIDevice->HeaderType);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverCode Driver::DriverLoadBindPCI(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf)
|
||||||
|
{
|
||||||
|
UNUSED(IsElf);
|
||||||
|
for (unsigned long Vidx = 0; Vidx < sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID) / sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID[0]); Vidx++)
|
||||||
|
{
|
||||||
|
for (unsigned long Didx = 0; Didx < sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID) / sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID[0]); Didx++)
|
||||||
|
{
|
||||||
|
if (Vidx >= sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID) && Didx >= sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID[Vidx] == 0 || ((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID[Didx] == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::vector<PCI::PCIDeviceHeader *> devices = PCIManager->FindPCIDevice(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID[Vidx], ((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID[Didx]);
|
||||||
|
if (devices.size() == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (auto PCIDevice in devices)
|
||||||
|
{
|
||||||
|
debug("[%ld] VendorID: %#x; DeviceID: %#x", devices.size(), PCIDevice->VendorID, PCIDevice->DeviceID);
|
||||||
|
Memory::MemMgr *mem = new Memory::MemMgr(nullptr, TaskManager->GetCurrentProcess()->memDirectory);
|
||||||
|
Fex *fex = (Fex *)mem->RequestPages(TO_PAGES(Size + 1));
|
||||||
|
memcpy(fex, (void *)DriverAddress, Size);
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
debug("Driver allocated at %#lx-%#lx", fex, (uintptr_t)fex + Size);
|
||||||
|
#ifdef DEBUG
|
||||||
|
uint8_t *result = md5File((uint8_t *)fex, Size);
|
||||||
|
debug("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||||
|
result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7],
|
||||||
|
result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15]);
|
||||||
|
kfree(result);
|
||||||
|
#endif
|
||||||
|
KernelAPI *KAPI = (KernelAPI *)mem->RequestPages(TO_PAGES(sizeof(KernelAPI) + 1));
|
||||||
|
|
||||||
|
if (CallDriverEntryPoint(fex, KAPI) != DriverCode::OK)
|
||||||
|
{
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::DRIVER_RETURNED_ERROR;
|
||||||
|
}
|
||||||
|
debug("Starting driver %s", fexExtended->Driver.Name);
|
||||||
|
|
||||||
|
MapPCIAddresses(PCIDevice);
|
||||||
|
|
||||||
|
switch (fexExtended->Driver.Type)
|
||||||
|
{
|
||||||
|
case FexDriverType::FexDriverType_Generic:
|
||||||
|
return BindPCIGeneric(mem, fex, PCIDevice);
|
||||||
|
case FexDriverType::FexDriverType_Display:
|
||||||
|
return BindPCIDisplay(mem, fex, PCIDevice);
|
||||||
|
case FexDriverType::FexDriverType_Network:
|
||||||
|
return BindPCINetwork(mem, fex, PCIDevice);
|
||||||
|
case FexDriverType::FexDriverType_Storage:
|
||||||
|
return BindPCIStorage(mem, fex, PCIDevice);
|
||||||
|
case FexDriverType::FexDriverType_FileSystem:
|
||||||
|
return BindPCIFileSystem(mem, fex, PCIDevice);
|
||||||
|
case FexDriverType::FexDriverType_Input:
|
||||||
|
return BindPCIInput(mem, fex, PCIDevice);
|
||||||
|
case FexDriverType::FexDriverType_Audio:
|
||||||
|
return BindPCIAudio(mem, fex, PCIDevice);
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
warn("Unknown driver type: %d", fexExtended->Driver.Type);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::UNKNOWN_DRIVER_TYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DriverCode::PCI_DEVICE_NOT_FOUND;
|
||||||
|
}
|
||||||
|
}
|
@ -31,41 +31,6 @@
|
|||||||
|
|
||||||
namespace Driver
|
namespace Driver
|
||||||
{
|
{
|
||||||
DriverCode Driver::BindProcessGeneric(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindProcessDisplay(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindProcessNetwork(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindProcessStorage(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindProcessFileSystem(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindProcessInput(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindProcessAudio(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::DriverLoadBindProcess(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf)
|
DriverCode Driver::DriverLoadBindProcess(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf)
|
||||||
{
|
{
|
||||||
fixme("Process driver: %s", ((FexExtended *)DrvExtHdr)->Driver.Name);
|
fixme("Process driver: %s", ((FexExtended *)DrvExtHdr)->Driver.Name);
|
38
Core/Driver/DriverBinding/Input/Audio.cpp
Normal file
38
Core/Driver/DriverBinding/Input/Audio.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInputAudio(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
38
Core/Driver/DriverBinding/Input/Display.cpp
Normal file
38
Core/Driver/DriverBinding/Input/Display.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInputDisplay(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
38
Core/Driver/DriverBinding/Input/Filesystem.cpp
Normal file
38
Core/Driver/DriverBinding/Input/Filesystem.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInputFileSystem(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
38
Core/Driver/DriverBinding/Input/Generic.cpp
Normal file
38
Core/Driver/DriverBinding/Input/Generic.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInputGeneric(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
67
Core/Driver/DriverBinding/Input/Input.cpp
Normal file
67
Core/Driver/DriverBinding/Input/Input.cpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInputInput(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
KernelCallback KCallback{};
|
||||||
|
|
||||||
|
fixme("Input driver: %s", fexExtended->Driver.Name);
|
||||||
|
KCallback.RawPtr = nullptr;
|
||||||
|
KCallback.Reason = CallbackReason::ConfigurationReason;
|
||||||
|
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(&KCallback);
|
||||||
|
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
||||||
|
{
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
error("Driver %s is not implemented", fexExtended->Driver.Name);
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
else if (CallbackRet != DriverReturnCode::OK)
|
||||||
|
{
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
error("Driver %s returned error %d", fexExtended->Driver.Name, CallbackRet);
|
||||||
|
return DriverCode::DRIVER_RETURNED_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
fixme("Input driver: %s", fexExtended->Driver.Name);
|
||||||
|
|
||||||
|
DriverFile DrvFile = {
|
||||||
|
.Enabled = true,
|
||||||
|
.DriverUID = this->DriverUIDs - 1,
|
||||||
|
.Address = (void *)fex,
|
||||||
|
.MemTrk = mem,
|
||||||
|
};
|
||||||
|
Drivers.push_back(DrvFile);
|
||||||
|
return DriverCode::OK;
|
||||||
|
}
|
||||||
|
}
|
38
Core/Driver/DriverBinding/Input/Network.cpp
Normal file
38
Core/Driver/DriverBinding/Input/Network.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInputNetwork(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
38
Core/Driver/DriverBinding/Input/Storage.cpp
Normal file
38
Core/Driver/DriverBinding/Input/Storage.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInputStorage(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
81
Core/Driver/DriverBinding/Interrupt/Audio.cpp
Normal file
81
Core/Driver/DriverBinding/Interrupt/Audio.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInterruptAudio(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fixme("Audio driver: %s", fexExtended->Driver.Name);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
81
Core/Driver/DriverBinding/Interrupt/Display.cpp
Normal file
81
Core/Driver/DriverBinding/Interrupt/Display.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInterruptDisplay(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fixme("Display driver: %s", fexExtended->Driver.Name);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
81
Core/Driver/DriverBinding/Interrupt/Filesystem.cpp
Normal file
81
Core/Driver/DriverBinding/Interrupt/Filesystem.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInterruptFileSystem(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fixme("Filesystem driver: %s", fexExtended->Driver.Name);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
88
Core/Driver/DriverBinding/Interrupt/Generic.cpp
Normal file
88
Core/Driver/DriverBinding/Interrupt/Generic.cpp
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInterruptGeneric(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fixme("Generic driver: %s", fexExtended->Driver.Name);
|
||||||
|
DriverFile DrvFile = {
|
||||||
|
.Enabled = true,
|
||||||
|
.DriverUID = this->DriverUIDs - 1,
|
||||||
|
.Address = (void *)fex,
|
||||||
|
.InterruptCallback = (void *)((uintptr_t)fex + (uintptr_t)fexExtended->Driver.InterruptCallback),
|
||||||
|
.MemTrk = mem,
|
||||||
|
};
|
||||||
|
Drivers.push_back(DrvFile);
|
||||||
|
return DriverCode::OK;
|
||||||
|
}
|
||||||
|
}
|
124
Core/Driver/DriverBinding/Interrupt/Input.cpp
Normal file
124
Core/Driver/DriverBinding/Interrupt/Input.cpp
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInterruptInput(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
debug("Searching for conflicting drivers...");
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if ((fe->Driver.TypeFlags & FexDriverInputTypes_Mouse &&
|
||||||
|
fexExtended->Driver.TypeFlags & FexDriverInputTypes_Mouse) ||
|
||||||
|
(fe->Driver.TypeFlags & FexDriverInputTypes_Keyboard &&
|
||||||
|
fexExtended->Driver.TypeFlags & FexDriverInputTypes_Keyboard))
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if ((fe->Driver.TypeFlags & FexDriverInputTypes_Mouse &&
|
||||||
|
fexExtended->Driver.TypeFlags & FexDriverInputTypes_Mouse) ||
|
||||||
|
(fe->Driver.TypeFlags & FexDriverInputTypes_Keyboard &&
|
||||||
|
fexExtended->Driver.TypeFlags & FexDriverInputTypes_Keyboard))
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverFile DrvFile = {
|
||||||
|
.Enabled = true,
|
||||||
|
.DriverUID = this->DriverUIDs - 1,
|
||||||
|
.Address = (void *)fex,
|
||||||
|
.InterruptCallback = (void *)((uintptr_t)fex + (uintptr_t)fexExtended->Driver.InterruptCallback),
|
||||||
|
.MemTrk = mem,
|
||||||
|
};
|
||||||
|
if (fexExtended->Driver.InterruptCallback)
|
||||||
|
{
|
||||||
|
for (unsigned long i = 0; i < sizeof(fexExtended->Driver.Bind.Interrupt.Vector) / sizeof(fexExtended->Driver.Bind.Interrupt.Vector[0]); i++)
|
||||||
|
{
|
||||||
|
if (fexExtended->Driver.Bind.Interrupt.Vector[i] == 0)
|
||||||
|
break;
|
||||||
|
DrvFile.InterruptHook[i] = new DriverInterruptHook(fexExtended->Driver.Bind.Interrupt.Vector[i], DrvFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
KernelCallback KCallback{};
|
||||||
|
KCallback.RawPtr = nullptr;
|
||||||
|
KCallback.Reason = CallbackReason::ConfigurationReason;
|
||||||
|
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(&KCallback);
|
||||||
|
|
||||||
|
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
||||||
|
{
|
||||||
|
error("Driver %s is not implemented", fexExtended->Driver.Name);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
else if (CallbackRet != DriverReturnCode::OK)
|
||||||
|
{
|
||||||
|
error("Driver %s returned error %d", fexExtended->Driver.Name, CallbackRet);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::DRIVER_RETURNED_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
Drivers.push_back(DrvFile);
|
||||||
|
return DriverCode::OK;
|
||||||
|
}
|
||||||
|
}
|
81
Core/Driver/DriverBinding/Interrupt/Network.cpp
Normal file
81
Core/Driver/DriverBinding/Interrupt/Network.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInterruptNetwork(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fixme("Network driver: %s", fexExtended->Driver.Name);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
115
Core/Driver/DriverBinding/Interrupt/Storage.cpp
Normal file
115
Core/Driver/DriverBinding/Interrupt/Storage.cpp
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindInterruptStorage(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverFile DrvFile = {
|
||||||
|
.Enabled = true,
|
||||||
|
.DriverUID = this->DriverUIDs - 1,
|
||||||
|
.Address = (void *)fex,
|
||||||
|
.InterruptCallback = (void *)((uintptr_t)fex + (uintptr_t)fexExtended->Driver.InterruptCallback),
|
||||||
|
.MemTrk = mem,
|
||||||
|
};
|
||||||
|
if (fexExtended->Driver.InterruptCallback)
|
||||||
|
{
|
||||||
|
for (unsigned long i = 0; i < sizeof(fexExtended->Driver.Bind.Interrupt.Vector) / sizeof(fexExtended->Driver.Bind.Interrupt.Vector[0]); i++)
|
||||||
|
{
|
||||||
|
if (fexExtended->Driver.Bind.Interrupt.Vector[i] == 0)
|
||||||
|
break;
|
||||||
|
DrvFile.InterruptHook[i] = new DriverInterruptHook(fexExtended->Driver.Bind.Interrupt.Vector[i], DrvFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
KernelCallback KCallback{};
|
||||||
|
KCallback.RawPtr = nullptr;
|
||||||
|
KCallback.Reason = CallbackReason::ConfigurationReason;
|
||||||
|
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(&KCallback);
|
||||||
|
|
||||||
|
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
||||||
|
{
|
||||||
|
error("Driver %s is not implemented", fexExtended->Driver.Name);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
else if (CallbackRet != DriverReturnCode::OK)
|
||||||
|
{
|
||||||
|
error("Driver %s returned error %d", fexExtended->Driver.Name, CallbackRet);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::DRIVER_RETURNED_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
Drivers.push_back(DrvFile);
|
||||||
|
return DriverCode::OK;
|
||||||
|
}
|
||||||
|
}
|
110
Core/Driver/DriverBinding/PCI/Audio.cpp
Normal file
110
Core/Driver/DriverBinding/PCI/Audio.cpp
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindPCIAudio(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverFile DrvFile = {
|
||||||
|
.Enabled = true,
|
||||||
|
.DriverUID = this->DriverUIDs - 1,
|
||||||
|
.Address = (void *)fex,
|
||||||
|
.InterruptCallback = (void *)((uintptr_t)fex + (uintptr_t)fexExtended->Driver.InterruptCallback),
|
||||||
|
.MemTrk = mem,
|
||||||
|
};
|
||||||
|
if (fexExtended->Driver.InterruptCallback)
|
||||||
|
DrvFile.InterruptHook[0] = new DriverInterruptHook(((int)((PCI::PCIHeader0 *)PCIDevice)->InterruptLine), DrvFile);
|
||||||
|
|
||||||
|
KernelCallback KCallback{};
|
||||||
|
KCallback.RawPtr = PCIDevice;
|
||||||
|
KCallback.Reason = CallbackReason::ConfigurationReason;
|
||||||
|
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(&KCallback);
|
||||||
|
|
||||||
|
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
||||||
|
{
|
||||||
|
error("Driver %s is not implemented", fexExtended->Driver.Name);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
else if (CallbackRet == DriverReturnCode::OK)
|
||||||
|
trace("Device found for driver: %s", fexExtended->Driver.Name);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error("Driver %s returned error %d", fexExtended->Driver.Name, CallbackRet);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::DRIVER_RETURNED_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
Drivers.push_back(DrvFile);
|
||||||
|
return DriverCode::OK;
|
||||||
|
}
|
||||||
|
}
|
81
Core/Driver/DriverBinding/PCI/Display.cpp
Normal file
81
Core/Driver/DriverBinding/PCI/Display.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindPCIDisplay(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fixme("Display driver: %s", fexExtended->Driver.Name);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
81
Core/Driver/DriverBinding/PCI/Filesystem.cpp
Normal file
81
Core/Driver/DriverBinding/PCI/Filesystem.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindPCIFileSystem(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fixme("Filesystem driver: %s", fexExtended->Driver.Name);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
81
Core/Driver/DriverBinding/PCI/Generic.cpp
Normal file
81
Core/Driver/DriverBinding/PCI/Generic.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindPCIGeneric(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fixme("Generic driver: %s", fexExtended->Driver.Name);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
81
Core/Driver/DriverBinding/PCI/Input.cpp
Normal file
81
Core/Driver/DriverBinding/PCI/Input.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindPCIInput(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fixme("Input driver: %s", fexExtended->Driver.Name);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
110
Core/Driver/DriverBinding/PCI/Network.cpp
Normal file
110
Core/Driver/DriverBinding/PCI/Network.cpp
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindPCINetwork(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverFile DrvFile = {
|
||||||
|
.Enabled = true,
|
||||||
|
.DriverUID = this->DriverUIDs - 1,
|
||||||
|
.Address = (void *)fex,
|
||||||
|
.InterruptCallback = (void *)((uintptr_t)fex + (uintptr_t)fexExtended->Driver.InterruptCallback),
|
||||||
|
.MemTrk = mem,
|
||||||
|
};
|
||||||
|
if (fexExtended->Driver.InterruptCallback)
|
||||||
|
DrvFile.InterruptHook[0] = new DriverInterruptHook(((int)((PCI::PCIHeader0 *)PCIDevice)->InterruptLine), DrvFile);
|
||||||
|
|
||||||
|
KernelCallback KCallback{};
|
||||||
|
KCallback.RawPtr = PCIDevice;
|
||||||
|
KCallback.Reason = CallbackReason::ConfigurationReason;
|
||||||
|
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(&KCallback);
|
||||||
|
|
||||||
|
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
||||||
|
{
|
||||||
|
error("Driver %s is not implemented", fexExtended->Driver.Name);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
else if (CallbackRet == DriverReturnCode::OK)
|
||||||
|
trace("Device found for driver: %s", fexExtended->Driver.Name);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error("Driver %s returned error %d", fexExtended->Driver.Name, CallbackRet);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::DRIVER_RETURNED_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
Drivers.push_back(DrvFile);
|
||||||
|
return DriverCode::OK;
|
||||||
|
}
|
||||||
|
}
|
110
Core/Driver/DriverBinding/PCI/Storage.cpp
Normal file
110
Core/Driver/DriverBinding/PCI/Storage.cpp
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindPCIStorage(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
||||||
|
{
|
||||||
|
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
||||||
|
|
||||||
|
if (fexExtended->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
|
||||||
|
DriversToRemove.push_back(Drv.DriverUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (auto DrvID in DriversToRemove)
|
||||||
|
{
|
||||||
|
if (!this->UnloadDriver(DrvID))
|
||||||
|
{
|
||||||
|
error("Failed to unload conflicting driver %d", DrvID);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (auto Drv in Drivers)
|
||||||
|
{
|
||||||
|
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
||||||
|
|
||||||
|
if (fe->Driver.OverrideOnConflict)
|
||||||
|
{
|
||||||
|
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
||||||
|
return DriverCode::DRIVER_CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DriverFile DrvFile = {
|
||||||
|
.Enabled = true,
|
||||||
|
.DriverUID = this->DriverUIDs - 1,
|
||||||
|
.Address = (void *)fex,
|
||||||
|
.InterruptCallback = (void *)((uintptr_t)fex + (uintptr_t)fexExtended->Driver.InterruptCallback),
|
||||||
|
.MemTrk = mem,
|
||||||
|
};
|
||||||
|
if (fexExtended->Driver.InterruptCallback)
|
||||||
|
DrvFile.InterruptHook[0] = new DriverInterruptHook(((int)((PCI::PCIHeader0 *)PCIDevice)->InterruptLine), DrvFile);
|
||||||
|
|
||||||
|
KernelCallback KCallback{};
|
||||||
|
KCallback.RawPtr = PCIDevice;
|
||||||
|
KCallback.Reason = CallbackReason::ConfigurationReason;
|
||||||
|
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(&KCallback);
|
||||||
|
|
||||||
|
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
||||||
|
{
|
||||||
|
error("Driver %s is not implemented", fexExtended->Driver.Name);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
else if (CallbackRet == DriverReturnCode::OK)
|
||||||
|
trace("Device found for driver: %s", fexExtended->Driver.Name);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error("Driver %s returned error %d", fexExtended->Driver.Name, CallbackRet);
|
||||||
|
delete mem, mem = nullptr;
|
||||||
|
return DriverCode::DRIVER_RETURNED_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
Drivers.push_back(DrvFile);
|
||||||
|
return DriverCode::OK;
|
||||||
|
}
|
||||||
|
}
|
38
Core/Driver/DriverBinding/Process/Audio.cpp
Normal file
38
Core/Driver/DriverBinding/Process/Audio.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindProcessAudio(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
38
Core/Driver/DriverBinding/Process/Display.cpp
Normal file
38
Core/Driver/DriverBinding/Process/Display.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindProcessDisplay(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
38
Core/Driver/DriverBinding/Process/Filesystem.cpp
Normal file
38
Core/Driver/DriverBinding/Process/Filesystem.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindProcessFileSystem(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
38
Core/Driver/DriverBinding/Process/Generic.cpp
Normal file
38
Core/Driver/DriverBinding/Process/Generic.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindProcessGeneric(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
38
Core/Driver/DriverBinding/Process/Input.cpp
Normal file
38
Core/Driver/DriverBinding/Process/Input.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindProcessInput(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
38
Core/Driver/DriverBinding/Process/Network.cpp
Normal file
38
Core/Driver/DriverBinding/Process/Network.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindProcessNetwork(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
38
Core/Driver/DriverBinding/Process/Storage.cpp
Normal file
38
Core/Driver/DriverBinding/Process/Storage.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Fennix Kernel.
|
||||||
|
|
||||||
|
Fennix Kernel is free software: you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
Fennix Kernel is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../api.hpp"
|
||||||
|
|
||||||
|
#include <ints.hpp>
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <task.hpp>
|
||||||
|
#include <lock.hpp>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <cwalk.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include "../../../../kernel.h"
|
||||||
|
#include "../../../../DAPI.hpp"
|
||||||
|
#include "../../../../Fex.hpp"
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
DriverCode Driver::BindProcessStorage(Memory::MemMgr *mem, void *fex)
|
||||||
|
{
|
||||||
|
return DriverCode::NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
@ -1,504 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of Fennix Kernel.
|
|
||||||
|
|
||||||
Fennix Kernel is free software: you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation, either version 3 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
Fennix Kernel is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "../api.hpp"
|
|
||||||
|
|
||||||
#include <ints.hpp>
|
|
||||||
#include <memory.hpp>
|
|
||||||
#include <task.hpp>
|
|
||||||
#include <lock.hpp>
|
|
||||||
#include <printf.h>
|
|
||||||
#include <cwalk.h>
|
|
||||||
#include <md5.h>
|
|
||||||
|
|
||||||
#include "../../../kernel.h"
|
|
||||||
#include "../../../DAPI.hpp"
|
|
||||||
#include "../../../Fex.hpp"
|
|
||||||
|
|
||||||
namespace Driver
|
|
||||||
{
|
|
||||||
DriverCode Driver::BindInterruptGeneric(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fixme("Generic driver: %s", fexExtended->Driver.Name);
|
|
||||||
DriverFile DrvFile = {
|
|
||||||
.Enabled = true,
|
|
||||||
.DriverUID = this->DriverUIDs - 1,
|
|
||||||
.Address = (void *)fex,
|
|
||||||
.InterruptCallback = (void *)((uintptr_t)fex + (uintptr_t)fexExtended->Driver.InterruptCallback),
|
|
||||||
.MemTrk = mem,
|
|
||||||
};
|
|
||||||
Drivers.push_back(DrvFile);
|
|
||||||
return DriverCode::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindInterruptDisplay(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fixme("Display driver: %s", fexExtended->Driver.Name);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindInterruptNetwork(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fixme("Network driver: %s", fexExtended->Driver.Name);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindInterruptStorage(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
return DriverCode::NOT_IMPLEMENTED; // FIXME
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DriverFile DrvFile = {
|
|
||||||
.Enabled = true,
|
|
||||||
.DriverUID = this->DriverUIDs - 1,
|
|
||||||
.Address = (void *)fex,
|
|
||||||
.InterruptCallback = (void *)((uintptr_t)fex + (uintptr_t)fexExtended->Driver.InterruptCallback),
|
|
||||||
.MemTrk = mem,
|
|
||||||
};
|
|
||||||
if (fexExtended->Driver.InterruptCallback)
|
|
||||||
{
|
|
||||||
for (unsigned long i = 0; i < sizeof(fexExtended->Driver.Bind.Interrupt.Vector) / sizeof(fexExtended->Driver.Bind.Interrupt.Vector[0]); i++)
|
|
||||||
{
|
|
||||||
if (fexExtended->Driver.Bind.Interrupt.Vector[i] == 0)
|
|
||||||
break;
|
|
||||||
DrvFile.InterruptHook[i] = new DriverInterruptHook(fexExtended->Driver.Bind.Interrupt.Vector[i], DrvFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
KernelCallback KCallback = {.raw = 0};
|
|
||||||
KCallback.RawPtr = nullptr;
|
|
||||||
KCallback.Reason = CallbackReason::ConfigurationReason;
|
|
||||||
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(&KCallback);
|
|
||||||
|
|
||||||
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
|
||||||
{
|
|
||||||
error("Driver %s is not implemented", fexExtended->Driver.Name);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
else if (CallbackRet != DriverReturnCode::OK)
|
|
||||||
{
|
|
||||||
error("Driver %s returned error %d", fexExtended->Driver.Name, CallbackRet);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::DRIVER_RETURNED_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
Drivers.push_back(DrvFile);
|
|
||||||
return DriverCode::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindInterruptFileSystem(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fixme("Filesystem driver: %s", fexExtended->Driver.Name);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindInterruptInput(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
debug("Searching for conflicting drivers...");
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if ((fe->Driver.TypeFlags & FexDriverInputTypes_Mouse &&
|
|
||||||
fexExtended->Driver.TypeFlags & FexDriverInputTypes_Mouse) ||
|
|
||||||
(fe->Driver.TypeFlags & FexDriverInputTypes_Keyboard &&
|
|
||||||
fexExtended->Driver.TypeFlags & FexDriverInputTypes_Keyboard))
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if ((fe->Driver.TypeFlags & FexDriverInputTypes_Mouse &&
|
|
||||||
fexExtended->Driver.TypeFlags & FexDriverInputTypes_Mouse) ||
|
|
||||||
(fe->Driver.TypeFlags & FexDriverInputTypes_Keyboard &&
|
|
||||||
fexExtended->Driver.TypeFlags & FexDriverInputTypes_Keyboard))
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverFile DrvFile = {
|
|
||||||
.Enabled = true,
|
|
||||||
.DriverUID = this->DriverUIDs - 1,
|
|
||||||
.Address = (void *)fex,
|
|
||||||
.InterruptCallback = (void *)((uintptr_t)fex + (uintptr_t)fexExtended->Driver.InterruptCallback),
|
|
||||||
.MemTrk = mem,
|
|
||||||
};
|
|
||||||
if (fexExtended->Driver.InterruptCallback)
|
|
||||||
{
|
|
||||||
for (unsigned long i = 0; i < sizeof(fexExtended->Driver.Bind.Interrupt.Vector) / sizeof(fexExtended->Driver.Bind.Interrupt.Vector[0]); i++)
|
|
||||||
{
|
|
||||||
if (fexExtended->Driver.Bind.Interrupt.Vector[i] == 0)
|
|
||||||
break;
|
|
||||||
DrvFile.InterruptHook[i] = new DriverInterruptHook(fexExtended->Driver.Bind.Interrupt.Vector[i], DrvFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
KernelCallback KCallback = {.raw = 0};
|
|
||||||
KCallback.RawPtr = nullptr;
|
|
||||||
KCallback.Reason = CallbackReason::ConfigurationReason;
|
|
||||||
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(&KCallback);
|
|
||||||
|
|
||||||
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
|
||||||
{
|
|
||||||
error("Driver %s is not implemented", fexExtended->Driver.Name);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
else if (CallbackRet != DriverReturnCode::OK)
|
|
||||||
{
|
|
||||||
error("Driver %s returned error %d", fexExtended->Driver.Name, CallbackRet);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::DRIVER_RETURNED_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
Drivers.push_back(DrvFile);
|
|
||||||
return DriverCode::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindInterruptAudio(Memory::MemMgr *mem, void *fex)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fixme("Audio driver: %s", fexExtended->Driver.Name);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::DriverLoadBindInterrupt(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf)
|
|
||||||
{
|
|
||||||
UNUSED(IsElf);
|
|
||||||
Memory::MemMgr *mem = new Memory::MemMgr(nullptr, TaskManager->GetCurrentProcess()->memDirectory);
|
|
||||||
Fex *fex = (Fex *)mem->RequestPages(TO_PAGES(Size + 1));
|
|
||||||
memcpy(fex, (void *)DriverAddress, Size);
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
debug("Driver allocated at %#lx-%#lx", fex, (uintptr_t)fex + Size);
|
|
||||||
#ifdef DEBUG
|
|
||||||
uint8_t *result = md5File((uint8_t *)fex, Size);
|
|
||||||
debug("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
|
||||||
result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7],
|
|
||||||
result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15]);
|
|
||||||
kfree(result);
|
|
||||||
#endif
|
|
||||||
KernelAPI *KAPI = (KernelAPI *)mem->RequestPages(TO_PAGES(sizeof(KernelAPI) + 1));
|
|
||||||
|
|
||||||
if (CallDriverEntryPoint(fex, KAPI) != DriverCode::OK)
|
|
||||||
{
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::DRIVER_RETURNED_ERROR;
|
|
||||||
}
|
|
||||||
debug("Starting driver %s (offset: %#lx)", fexExtended->Driver.Name, fex);
|
|
||||||
|
|
||||||
switch (fexExtended->Driver.Type)
|
|
||||||
{
|
|
||||||
case FexDriverType::FexDriverType_Generic:
|
|
||||||
return BindInterruptGeneric(mem, fex);
|
|
||||||
case FexDriverType::FexDriverType_Display:
|
|
||||||
return BindInterruptDisplay(mem, fex);
|
|
||||||
case FexDriverType::FexDriverType_Network:
|
|
||||||
return BindInterruptNetwork(mem, fex);
|
|
||||||
case FexDriverType::FexDriverType_Storage:
|
|
||||||
return BindInterruptStorage(mem, fex);
|
|
||||||
case FexDriverType::FexDriverType_FileSystem:
|
|
||||||
return BindInterruptFileSystem(mem, fex);
|
|
||||||
case FexDriverType::FexDriverType_Input:
|
|
||||||
return BindInterruptInput(mem, fex);
|
|
||||||
case FexDriverType::FexDriverType_Audio:
|
|
||||||
return BindInterruptAudio(mem, fex);
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
warn("Unknown driver type: %d", fexExtended->Driver.Type);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::UNKNOWN_DRIVER_TYPE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return DriverCode::OK;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,629 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of Fennix Kernel.
|
|
||||||
|
|
||||||
Fennix Kernel is free software: you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License as
|
|
||||||
published by the Free Software Foundation, either version 3 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
Fennix Kernel is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "../api.hpp"
|
|
||||||
|
|
||||||
#include <ints.hpp>
|
|
||||||
#include <memory.hpp>
|
|
||||||
#include <task.hpp>
|
|
||||||
#include <lock.hpp>
|
|
||||||
#include <printf.h>
|
|
||||||
#include <cwalk.h>
|
|
||||||
#include <md5.h>
|
|
||||||
|
|
||||||
#include "../../../kernel.h"
|
|
||||||
#include "../../../DAPI.hpp"
|
|
||||||
#include "../../../Fex.hpp"
|
|
||||||
|
|
||||||
namespace Driver
|
|
||||||
{
|
|
||||||
void Driver::MapPCIAddresses(PCI::PCIDeviceHeader *PCIDevice)
|
|
||||||
{
|
|
||||||
debug("Header Type: %d", PCIDevice->HeaderType);
|
|
||||||
switch (PCIDevice->HeaderType)
|
|
||||||
{
|
|
||||||
case 0: // PCI Header 0
|
|
||||||
{
|
|
||||||
uint32_t BAR[6] = {0};
|
|
||||||
size_t BARsSize[6] = {0};
|
|
||||||
|
|
||||||
BAR[0] = ((PCI::PCIHeader0 *)PCIDevice)->BAR0;
|
|
||||||
BAR[1] = ((PCI::PCIHeader0 *)PCIDevice)->BAR1;
|
|
||||||
BAR[2] = ((PCI::PCIHeader0 *)PCIDevice)->BAR2;
|
|
||||||
BAR[3] = ((PCI::PCIHeader0 *)PCIDevice)->BAR3;
|
|
||||||
BAR[4] = ((PCI::PCIHeader0 *)PCIDevice)->BAR4;
|
|
||||||
BAR[5] = ((PCI::PCIHeader0 *)PCIDevice)->BAR5;
|
|
||||||
|
|
||||||
uintptr_t BAR_Type = BAR[0] & 1;
|
|
||||||
uintptr_t BAR_IOBase = BAR[1] & (~3);
|
|
||||||
uintptr_t BAR_MemoryBase = BAR[0] & (~15);
|
|
||||||
|
|
||||||
debug("Type: %d; IOBase: %#lx; MemoryBase: %#lx", BAR_Type, BAR_IOBase, BAR_MemoryBase);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
if (BAR[i] == 0)
|
|
||||||
continue;
|
|
||||||
debug("BAR%d: %#lx", i, BAR[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* BARs Size */
|
|
||||||
for (size_t i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
if (BAR[i] == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ((BAR[i] & 1) == 0) // Memory Base
|
|
||||||
{
|
|
||||||
((PCI::PCIHeader0 *)PCIDevice)->BAR0 = 0xFFFFFFFF;
|
|
||||||
size_t size = ((PCI::PCIHeader0 *)PCIDevice)->BAR0;
|
|
||||||
((PCI::PCIHeader0 *)PCIDevice)->BAR0 = BAR[i];
|
|
||||||
BARsSize[i] = size & (~15);
|
|
||||||
BARsSize[i] = ~BARsSize[i] + 1;
|
|
||||||
BARsSize[i] = BARsSize[i] & 0xFFFFFFFF;
|
|
||||||
debug("BAR%dSize: %#lx", i, BARsSize[i]);
|
|
||||||
}
|
|
||||||
else if ((BAR[i] & 1) == 1) // I/O Base
|
|
||||||
{
|
|
||||||
((PCI::PCIHeader0 *)PCIDevice)->BAR1 = 0xFFFFFFFF;
|
|
||||||
size_t size = ((PCI::PCIHeader0 *)PCIDevice)->BAR1;
|
|
||||||
((PCI::PCIHeader0 *)PCIDevice)->BAR1 = BAR[i];
|
|
||||||
BARsSize[i] = size & (~3);
|
|
||||||
BARsSize[i] = ~BARsSize[i] + 1;
|
|
||||||
BARsSize[i] = BARsSize[i] & 0xFFFF;
|
|
||||||
debug("BAR%dSize: %#lx", i, BARsSize[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Mapping the BARs */
|
|
||||||
for (size_t i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
if (BAR[i] == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ((BAR[i] & 1) == 0) // Memory Base
|
|
||||||
{
|
|
||||||
uintptr_t BARBase = BAR[i] & (~15);
|
|
||||||
size_t BARSize = BARsSize[i];
|
|
||||||
|
|
||||||
debug("Mapping BAR%d from %#lx to %#lx", i, BARBase, BARBase + BARSize);
|
|
||||||
Memory::Virtual().Map((void *)BARBase, (void *)BARBase, BARSize, Memory::PTFlag::RW | Memory::PTFlag::PWT);
|
|
||||||
}
|
|
||||||
else if ((BAR[i] & 1) == 1) // I/O Base
|
|
||||||
{
|
|
||||||
uintptr_t BARBase = BAR[i] & (~3);
|
|
||||||
uintptr_t BARSize = BARsSize[i];
|
|
||||||
|
|
||||||
debug("Mapping BAR%d from %#x to %#x", i, BARBase, BARBase + BARSize);
|
|
||||||
Memory::Virtual().Map((void *)BARBase, (void *)BARBase, BARSize, Memory::PTFlag::RW | Memory::PTFlag::PWT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 1: // PCI Header 1 (PCI-to-PCI Bridge)
|
|
||||||
{
|
|
||||||
fixme("PCI Header 1 (PCI-to-PCI Bridge) not implemented yet");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 2: // PCI Header 2 (PCI-to-CardBus Bridge)
|
|
||||||
{
|
|
||||||
fixme("PCI Header 2 (PCI-to-CardBus Bridge) not implemented yet");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
error("Unknown header type %d", PCIDevice->HeaderType);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindPCIGeneric(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fixme("Generic driver: %s", fexExtended->Driver.Name);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindPCIDisplay(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fixme("Display driver: %s", fexExtended->Driver.Name);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindPCINetwork(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverFile DrvFile = {
|
|
||||||
.Enabled = true,
|
|
||||||
.DriverUID = this->DriverUIDs - 1,
|
|
||||||
.Address = (void *)fex,
|
|
||||||
.InterruptCallback = (void *)((uintptr_t)fex + (uintptr_t)fexExtended->Driver.InterruptCallback),
|
|
||||||
.MemTrk = mem,
|
|
||||||
};
|
|
||||||
if (fexExtended->Driver.InterruptCallback)
|
|
||||||
DrvFile.InterruptHook[0] = new DriverInterruptHook(((int)((PCI::PCIHeader0 *)PCIDevice)->InterruptLine), DrvFile);
|
|
||||||
|
|
||||||
KernelCallback KCallback = {.raw = 0};
|
|
||||||
KCallback.RawPtr = PCIDevice;
|
|
||||||
KCallback.Reason = CallbackReason::ConfigurationReason;
|
|
||||||
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(&KCallback);
|
|
||||||
|
|
||||||
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
|
||||||
{
|
|
||||||
error("Driver %s is not implemented", fexExtended->Driver.Name);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
else if (CallbackRet == DriverReturnCode::OK)
|
|
||||||
trace("Device found for driver: %s", fexExtended->Driver.Name);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
error("Driver %s returned error %d", fexExtended->Driver.Name, CallbackRet);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::DRIVER_RETURNED_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
Drivers.push_back(DrvFile);
|
|
||||||
return DriverCode::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindPCIStorage(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverFile DrvFile = {
|
|
||||||
.Enabled = true,
|
|
||||||
.DriverUID = this->DriverUIDs - 1,
|
|
||||||
.Address = (void *)fex,
|
|
||||||
.InterruptCallback = (void *)((uintptr_t)fex + (uintptr_t)fexExtended->Driver.InterruptCallback),
|
|
||||||
.MemTrk = mem,
|
|
||||||
};
|
|
||||||
if (fexExtended->Driver.InterruptCallback)
|
|
||||||
DrvFile.InterruptHook[0] = new DriverInterruptHook(((int)((PCI::PCIHeader0 *)PCIDevice)->InterruptLine), DrvFile);
|
|
||||||
|
|
||||||
KernelCallback KCallback = {.raw = 0};
|
|
||||||
KCallback.RawPtr = PCIDevice;
|
|
||||||
KCallback.Reason = CallbackReason::ConfigurationReason;
|
|
||||||
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(&KCallback);
|
|
||||||
|
|
||||||
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
|
||||||
{
|
|
||||||
error("Driver %s is not implemented", fexExtended->Driver.Name);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
else if (CallbackRet == DriverReturnCode::OK)
|
|
||||||
trace("Device found for driver: %s", fexExtended->Driver.Name);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
error("Driver %s returned error %d", fexExtended->Driver.Name, CallbackRet);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::DRIVER_RETURNED_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
Drivers.push_back(DrvFile);
|
|
||||||
return DriverCode::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindPCIFileSystem(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fixme("Filesystem driver: %s", fexExtended->Driver.Name);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindPCIInput(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fixme("Input driver: %s", fexExtended->Driver.Name);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::BindPCIAudio(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice)
|
|
||||||
{
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
|
|
||||||
if (fexExtended->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
std::vector<uint64_t> DriversToRemove = std::vector<uint64_t>();
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriversToRemove.push_back(Drv.DriverUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (auto DrvID in DriversToRemove)
|
|
||||||
{
|
|
||||||
if (!this->UnloadDriver(DrvID))
|
|
||||||
{
|
|
||||||
error("Failed to unload conflicting driver %d", DrvID);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (auto Drv in Drivers)
|
|
||||||
{
|
|
||||||
FexExtended *fe = ((FexExtended *)((uintptr_t)Drv.Address + EXTENDED_SECTION_ADDRESS));
|
|
||||||
|
|
||||||
if (fe->Driver.OverrideOnConflict)
|
|
||||||
{
|
|
||||||
debug("Driver %s is conflicting with %s", fe->Driver.Name, fexExtended->Driver.Name);
|
|
||||||
return DriverCode::DRIVER_CONFLICT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverFile DrvFile = {
|
|
||||||
.Enabled = true,
|
|
||||||
.DriverUID = this->DriverUIDs - 1,
|
|
||||||
.Address = (void *)fex,
|
|
||||||
.InterruptCallback = (void *)((uintptr_t)fex + (uintptr_t)fexExtended->Driver.InterruptCallback),
|
|
||||||
.MemTrk = mem,
|
|
||||||
};
|
|
||||||
if (fexExtended->Driver.InterruptCallback)
|
|
||||||
DrvFile.InterruptHook[0] = new DriverInterruptHook(((int)((PCI::PCIHeader0 *)PCIDevice)->InterruptLine), DrvFile);
|
|
||||||
|
|
||||||
KernelCallback KCallback = {.raw = 0};
|
|
||||||
KCallback.RawPtr = PCIDevice;
|
|
||||||
KCallback.Reason = CallbackReason::ConfigurationReason;
|
|
||||||
int CallbackRet = ((int (*)(KernelCallback *))((uintptr_t)fexExtended->Driver.Callback + (uintptr_t)fex))(&KCallback);
|
|
||||||
|
|
||||||
if (CallbackRet == DriverReturnCode::NOT_IMPLEMENTED)
|
|
||||||
{
|
|
||||||
error("Driver %s is not implemented", fexExtended->Driver.Name);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
else if (CallbackRet == DriverReturnCode::OK)
|
|
||||||
trace("Device found for driver: %s", fexExtended->Driver.Name);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
error("Driver %s returned error %d", fexExtended->Driver.Name, CallbackRet);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::DRIVER_RETURNED_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
Drivers.push_back(DrvFile);
|
|
||||||
return DriverCode::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverCode Driver::DriverLoadBindPCI(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf)
|
|
||||||
{
|
|
||||||
UNUSED(IsElf);
|
|
||||||
for (unsigned long Vidx = 0; Vidx < sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID) / sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID[0]); Vidx++)
|
|
||||||
{
|
|
||||||
for (unsigned long Didx = 0; Didx < sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID) / sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID[0]); Didx++)
|
|
||||||
{
|
|
||||||
if (Vidx >= sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID) && Didx >= sizeof(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID))
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID[Vidx] == 0 || ((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID[Didx] == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
std::vector<PCI::PCIDeviceHeader *> devices = PCIManager->FindPCIDevice(((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.VendorID[Vidx], ((FexExtended *)DrvExtHdr)->Driver.Bind.PCI.DeviceID[Didx]);
|
|
||||||
if (devices.size() == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
foreach (auto PCIDevice in devices)
|
|
||||||
{
|
|
||||||
debug("[%ld] VendorID: %#x; DeviceID: %#x", devices.size(), PCIDevice->VendorID, PCIDevice->DeviceID);
|
|
||||||
Memory::MemMgr *mem = new Memory::MemMgr(nullptr, TaskManager->GetCurrentProcess()->memDirectory);
|
|
||||||
Fex *fex = (Fex *)mem->RequestPages(TO_PAGES(Size + 1));
|
|
||||||
memcpy(fex, (void *)DriverAddress, Size);
|
|
||||||
FexExtended *fexExtended = (FexExtended *)((uintptr_t)fex + EXTENDED_SECTION_ADDRESS);
|
|
||||||
debug("Driver allocated at %#lx-%#lx", fex, (uintptr_t)fex + Size);
|
|
||||||
#ifdef DEBUG
|
|
||||||
uint8_t *result = md5File((uint8_t *)fex, Size);
|
|
||||||
debug("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
|
||||||
result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7],
|
|
||||||
result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15]);
|
|
||||||
kfree(result);
|
|
||||||
#endif
|
|
||||||
KernelAPI *KAPI = (KernelAPI *)mem->RequestPages(TO_PAGES(sizeof(KernelAPI) + 1));
|
|
||||||
|
|
||||||
if (CallDriverEntryPoint(fex, KAPI) != DriverCode::OK)
|
|
||||||
{
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::DRIVER_RETURNED_ERROR;
|
|
||||||
}
|
|
||||||
debug("Starting driver %s", fexExtended->Driver.Name);
|
|
||||||
|
|
||||||
MapPCIAddresses(PCIDevice);
|
|
||||||
|
|
||||||
switch (fexExtended->Driver.Type)
|
|
||||||
{
|
|
||||||
case FexDriverType::FexDriverType_Generic:
|
|
||||||
return BindPCIGeneric(mem, fex, PCIDevice);
|
|
||||||
case FexDriverType::FexDriverType_Display:
|
|
||||||
return BindPCIDisplay(mem, fex, PCIDevice);
|
|
||||||
case FexDriverType::FexDriverType_Network:
|
|
||||||
return BindPCINetwork(mem, fex, PCIDevice);
|
|
||||||
case FexDriverType::FexDriverType_Storage:
|
|
||||||
return BindPCIStorage(mem, fex, PCIDevice);
|
|
||||||
case FexDriverType::FexDriverType_FileSystem:
|
|
||||||
return BindPCIFileSystem(mem, fex, PCIDevice);
|
|
||||||
case FexDriverType::FexDriverType_Input:
|
|
||||||
return BindPCIInput(mem, fex, PCIDevice);
|
|
||||||
case FexDriverType::FexDriverType_Audio:
|
|
||||||
return BindPCIAudio(mem, fex, PCIDevice);
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
warn("Unknown driver type: %d", fexExtended->Driver.Type);
|
|
||||||
delete mem, mem = nullptr;
|
|
||||||
return DriverCode::UNKNOWN_DRIVER_TYPE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return DriverCode::PCI_DEVICE_NOT_FOUND;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user