Fix driver implementation

This commit is contained in:
EnderIce2
2024-07-07 03:15:17 +03:00
parent f85935f8f3
commit 4ecf37c44e
64 changed files with 2893 additions and 2863 deletions

View File

@ -20,7 +20,7 @@
#include <regs.h>
#include <base.h>
#include <pci.h>
#include <net.h>
#include <network.h>
#include <io.h>
#include "rtl8139.hpp"
@ -99,7 +99,11 @@ public:
uint16_t dataSz = *(data + 1);
data += 2;
ReportNetworkPacket(ID, data, dataSz);
// ReportNetworkPacket(ID, data, dataSz);
/* FIXME: Implement */
KernelLog("FIXME: Received packet");
(void)data;
(void)dataSz;
/* Update CAPR */
#define RX_READ_PTR_MASK (~0x3)
@ -169,7 +173,7 @@ public:
};
RTL8139Device *Drivers[4] = {nullptr};
dev_t AudioID[4] = {0};
dev_t NetID[4] = {(dev_t)-1};
#define OIR(x) OIR_##x
#define CREATE_OIR(x) \
@ -180,20 +184,40 @@ CREATE_OIR(1);
CREATE_OIR(2);
CREATE_OIR(3);
int drvOpen(dev_t, dev_t, int, mode_t) { return 0; }
int drvClose(dev_t, dev_t) { return 0; }
size_t drvRead(dev_t, dev_t, uint8_t *, size_t, off_t) { return 0; }
int __fs_Open(struct Inode *, int, mode_t) { return 0; }
int __fs_Close(struct Inode *) { return 0; }
ssize_t __fs_Read(struct Inode *, void *, size_t, off_t) { return 0; }
size_t drvWrite(dev_t, dev_t min, uint8_t *Buffer, size_t Size, off_t)
ssize_t __fs_Write(struct Inode *Node, const void *Buffer, size_t Size, off_t)
{
return Drivers[AudioID[min]]->write(Buffer, Size);
return Drivers[NetID[Node->GetMinor()]]->write((uint8_t *)Buffer, Size);
}
int drvIoctl(dev_t, dev_t min, unsigned long Request, void *Argp)
int __fs_Ioctl(struct Inode *Node, unsigned long Request, void *Argp)
{
return Drivers[AudioID[min]]->ioctl((NetIoctl)Request, Argp);
return Drivers[NetID[Node->GetMinor()]]->ioctl((NetIoctl)Request, Argp);
}
const struct InodeOperations NetOps = {
.Lookup = nullptr,
.Create = nullptr,
.Remove = nullptr,
.Rename = nullptr,
.Read = __fs_Read,
.Write = __fs_Write,
.Truncate = nullptr,
.Open = __fs_Open,
.Close = __fs_Close,
.Ioctl = __fs_Ioctl,
.ReadDir = nullptr,
.MkDir = nullptr,
.RmDir = nullptr,
.SymLink = nullptr,
.ReadLink = nullptr,
.Seek = nullptr,
.Stat = nullptr,
};
PCIArray *Devices;
EXTERNC int cxx_Panic()
{
@ -216,10 +240,10 @@ EXTERNC int cxx_Probe()
PCI_END};
uint16_t DeviceIDs[] = {0x8139, /* RTL8139 */
PCI_END};
Devices = FindPCIDevices(VendorIDs, DeviceIDs);
Devices = GetPCIDevices(VendorIDs, DeviceIDs);
if (Devices == nullptr)
{
Log("No RTL8139 device found.");
KernelLog("No RTL8139 device found.");
return -ENODEV;
}
return 0;
@ -240,11 +264,8 @@ EXTERNC int cxx_Initialize()
if (Drivers[Count]->IsInitialized())
{
dev_t ret = RegisterNetDevice(ddt_Network,
drvOpen, drvClose,
drvRead, drvWrite,
drvIoctl);
AudioID[Count] = ret;
dev_t ret = RegisterDevice(NETWORK_TYPE_ETHERNET, &NetOps);
NetID[Count] = ret;
Drivers[Count]->ID = ret;
/* FIXME: bad code */
@ -273,7 +294,7 @@ EXTERNC int cxx_Initialize()
if (Count == 0)
{
Log("No valid RTL8139 device found.");
KernelLog("No valid RTL8139 device found.");
return -EINVAL;
}
@ -294,5 +315,11 @@ EXTERNC int cxx_Finalize()
ctx = (PCIArray *)ctx->Next;
}
for (size_t i = 0; i < sizeof(NetID) / sizeof(dev_t); i++)
{
if (NetID[i] != (dev_t)-1)
UnregisterDevice(NetID[i]);
}
return 0;
}