* lib.c - Library Functions
*/
#include <acess.h>
+#include "../helpers.h"
// === IMPORTS ===
extern void __memcpy_align4(void *_dest, const void *_src, size_t _length);
return _dest;
}
-// Divide
-// - Find what power of two times Den is > Num
-// - Iterate down in bit significance
-// > If the `N` value is greater than `D`, we can set this bit
-#define DEF_DIVMOD(s) Uint##s __divmod##s(Uint##s N, Uint##s D, Uint##s*Rem){\
- Uint##s ret=0,add=1;\
- while(N>=D&&add) {D<<=1;add<<=1;}\
- while(add>1){\
- add>>=1;D>>=1;\
- if(N>=D){ret+=add;N-=D;}\
- }\
- if(Rem)*Rem = N;\
- return ret;\
-}
-
DEF_DIVMOD(64)
DEF_DIVMOD(32)
-
Uint64 DivMod64U(Uint64 Num, Uint64 Den, Uint64 *Rem)
{
Uint64 ret;
else
{
// Large page
- // TODO:
Log_Warning("MMVirt", "TODO: Implement large pages in MM_int_SetPageInfo");
}
break;
case 20: // Section or unmapped
- Warning("TODO: Implement sections");
+ Log_Warning("MMVirt", "TODO: Implement sections in MM_int_SetPageInfo");
break;
case 24: // Supersection
// Error if not aligned
{
if( pi->PhysAddr == 0 ) {
*desc = 0;
- // TODO: Apply to all entries
- LEAVE('i', 0);
- return 0;
}
- // Apply
- *desc = pi->PhysAddr & 0xFF000000;
-// *desc |= ((pi->PhysAddr >> 32) & 0xF) << 20;
-// *desc |= ((pi->PhysAddr >> 36) & 0x7) << 5;
- *desc |= 2 | (1 << 18);
+ else {
+ // Apply
+ *desc = pi->PhysAddr & 0xFF000000;
+// *desc |= ((pi->PhysAddr >> 32) & 0xF) << 20;
+// *desc |= ((pi->PhysAddr >> 36) & 0x7) << 5;
+ *desc |= 2 | (1 << 18);
+ }
// TODO: Apply to all entries
+ Log_Warning("MMVirt", "TODO: Apply changes to all entries of supersections");
LEAVE('i', 0);
return 0;
}
// TODO: What here?
+ Log_Warning("MMVirt", "TODO: 24-bit not on supersection?");
LEAVE('i', 1);
return 1;
}
return ret;
}
-tPAddr MM_ClearUser(void)
+void MM_ClearUser(void)
{
- // TODO: Implement ClearUser
- return 0;
+ Log_KernelPanic("MMVirt", "TODO: Implement MM_ClearUser");
}
tVAddr MM_MapTemp(tPAddr PAddr)
void MM_FreeTemp(tVAddr VAddr)
{
- // TODO: Implement FreeTemp
if( VAddr < MM_TMPMAP_BASE || VAddr >= MM_TMPMAP_END ) {
Log_Warning("MMVirt", "MM_FreeTemp: Passed an addr not from MM_MapTemp (%p)", VAddr);
return ;
*
*/
#include <acess.h>
+#include <drv_pci_int.h>
// Realview
//#define PCI_BASE 0x60000000
//#define PCI_BASE 0xF0400000 // VMM Mapping
#define PCI_BASE 0
-// === PROTOTYPES ===
-#if 1
-void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data);
-Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);
-Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);
-Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);
-#endif
-
// === CODE ===
-void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data)
+void PCI_CfgWriteDWord(Uint32 Addr, Uint32 Data)
{
#if PCI_BASE
- Uint32 address = PCI_BASE | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC);
- *(Uint32*)(address) = data;
+ Uint32 address = PCI_BASE | Addr;
+ *(Uint32*)(address) = Data;
#else
#endif
}
-Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)
+Uint32 PCI_CfgReadDWord(Uint32 Addr)
{
#if PCI_BASE
- Uint32 address = PCI_BASE | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC);
+ Uint32 address = PCI_BASE | Addr;
return *(Uint32*)address;
#else
return 0xFFFFFFFF;
#endif
}
-Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)
-{
- return PCI_CfgReadDWord(bus, dev, func, offset & ~3) >> (8*(offset&2));
-}
-
-Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)
-{
- return PCI_CfgReadDWord(bus, dev, func, offset & ~3) >> (8*(offset&3));
-}
#include <mm_virt.h>
#include <mm_phys.h>
#include <proc.h>
+#include <hal_proc.h>
#define TAB 22
void MM_PreinitVirtual(void);
void MM_InstallVirtual(void);
void MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs);
-void MM_DumpTables(tVAddr Start, tVAddr End);
-tVAddr MM_ClearUser(void);
+//void MM_DumpTables(tVAddr Start, tVAddr End);
+//void MM_ClearUser(void);
tPAddr MM_DuplicatePage(tVAddr VAddr);
// === GLOBALS ===
}
/**
- * \fn tVAddr MM_ClearUser()
* \brief Clear user's address space
*/
-tVAddr MM_ClearUser(void)
+void MM_ClearUser(void)
{
Uint i, j;
INVLPG( &gaPageTable[i*1024] );
}
INVLPG( gaPageDir );
-
- return *gpPageCR3;
}
/**
*/\r
#define DEBUG 0\r
#include <acess.h>\r
-\r
-// === PROTOTYPES ===\r
-Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
-void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data);\r
-Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
-Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
+#include <drv_pci_int.h>\r
\r
// === CODE ===\r
-Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)\r
-{\r
- Uint32 address;\r
- Uint32 data;\r
- \r
- bus &= 0xFF; // 8 Bits\r
- dev &= 0x1F; // 5 Bits\r
- func &= 0x7; // 3 Bits\r
- offset &= 0xFF; // 8 Bits\r
- \r
- address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC);\r
- outd(0xCF8, address);\r
- \r
- data = ind(0xCFC);\r
- //Debug("PCI(0x%x) = 0x%08x", address, data);\r
- return data;\r
-}\r
-void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data)\r
+Uint32 PCI_CfgReadDWord(Uint32 Address)\r
{\r
- Uint32 address;\r
- \r
- bus &= 0xFF; // 8 Bits\r
- dev &= 0x1F; // 5 Bits\r
- func &= 0x7; // 3 Bits\r
- offset &= 0xFF; // 8 Bits\r
- \r
- address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC);\r
- outd(0xCF8, address);\r
- outd(0xCFC, data);\r
-}\r
-Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)\r
-{\r
- Uint32 data = PCI_CfgReadDWord(bus, dev, func, offset);\r
- \r
- data >>= (offset&2)*8; // Allow Access to Upper Word\r
- \r
- return (Uint16)data;\r
+ Address |= 0x80000000;\r
+ outd(0xCF8, Address);\r
+ return ind(0xCFC);\r
}\r
\r
-Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)\r
+void PCI_CfgWriteDWord(Uint32 Address, Uint32 Data)\r
{\r
- Uint32 data = PCI_CfgReadDWord(bus, dev, func, offset);\r
- \r
- data >>= (offset&3)*8; //Allow Access to Upper Word\r
- return (Uint8)data;\r
+ Address |= 0x80000000;\r
+ outd(0xCF8, Address);\r
+ outd(0xCFC, Data);\r
}\r
-\r
#include <vfs.h>\r
#include <fs_devfs.h>\r
#include <drv_pci.h>\r
+#include <drv_pci_int.h>\r
\r
#define LIST_DEVICES 1\r
\r
-// === IMPORTS ===\r
-extern Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
-extern void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data);\r
-extern Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
-extern Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
-\r
// === STRUCTURES ===\r
typedef struct sPCIDevice\r
{\r
\r
char *PCI_int_ReadDirRoot(tVFS_Node *node, int pos);\r
tVFS_Node *PCI_int_FindDirRoot(tVFS_Node *node, const char *filename);\r
+Uint32 PCI_int_GetBusAddr(Uint16 Bus, Uint16 Slot, Uint16 Fcn, Uint8 Offset);\r
Uint64 PCI_int_ReadDevice(tVFS_Node *node, Uint64 pos, Uint64 length, void *buffer);\r
int PCI_int_EnumDevice(Uint16 bus, Uint16 dev, Uint16 fcn, tPCIDevice *info);\r
\r
return 0;\r
}\r
\r
+Uint32 PCI_int_GetBusAddr(Uint16 Bus, Uint16 Slot, Uint16 Fcn, Uint8 Offset)\r
+{\r
+ Bus &= 0xFF;\r
+ Slot &= 0x1F;\r
+ Fcn &= 7;\r
+ Offset &= 0xFC;\r
+ return ((Uint32)Bus << 16) | (Slot << 11) | (Fcn << 8) | (Offset & 0xFC);\r
+}\r
+\r
Uint32 PCI_ConfigRead(tPCIDev ID, int Offset, int Size)\r
{\r
tPCIDevice *dev;\r
- Uint32 dword;\r
+ Uint32 dword, addr;\r
+ \r
if( ID < 0 || ID >= giPCI_DeviceCount ) return 0;\r
if( Offset < 0 || Offset > 256 ) return 0;\r
\r
if( Offset & (Size - 1) ) return 0;\r
\r
dev = &gPCI_Devices[ID];\r
+ addr = PCI_int_GetBusAddr(dev->bus, dev->slot, dev->fcn, Offset);\r
\r
- dword = PCI_CfgReadDWord(dev->bus, dev->slot, dev->fcn, Offset / 4);\r
+ dword = PCI_CfgReadDWord(addr);\r
gPCI_Devices[ID].ConfigCache[Offset/4] = dword;\r
switch( Size )\r
{\r
void PCI_ConfigWrite(tPCIDev ID, int Offset, int Size, Uint32 Value)\r
{\r
tPCIDevice *dev;\r
- Uint32 dword;\r
+ Uint32 dword, addr;\r
int shift;\r
if( ID < 0 || ID >= giPCI_DeviceCount ) return ;\r
if( Offset < 0 || Offset > 256 ) return ;\r
\r
dev = &gPCI_Devices[ID];\r
+ addr = PCI_int_GetBusAddr(dev->bus, dev->slot, dev->fcn, Offset);\r
\r
if(Size != 4)\r
- dword = PCI_CfgReadDWord(dev->bus, dev->slot, dev->fcn, Offset/4);\r
+ dword = PCI_CfgReadDWord(addr);\r
switch(Size)\r
{\r
case 1:\r
default:\r
return;\r
}\r
- PCI_CfgWriteDWord(dev->bus, dev->slot, dev->fcn, Offset/4, dword);\r
+ PCI_CfgWriteDWord(addr, dword);\r
}\r
\r
/**\r
*/\r
int PCI_int_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info)\r
{\r
- Uint16 vendor;\r
+ Uint32 vendor_dev, tmp;\r
int i;\r
- \r
- vendor = PCI_CfgReadWord(bus, slot, fcn, 0x0|0);\r
- if(vendor == 0xFFFF) // Invalid Device\r
+ Uint32 addr;\r
+ addr = PCI_int_GetBusAddr(bus, slot, fcn, 0); \r
+\r
+ vendor_dev = PCI_CfgReadDWord( addr );\r
+ if((vendor_dev & 0xFFFF) == 0xFFFF) // Invalid Device\r
return 0;\r
- \r
+\r
+ info->ConfigCache[0] = vendor_dev;\r
+ for( i = 1; i < 256/4; i ++, addr += 4 )\r
+ {\r
+ info->ConfigCache[i] = PCI_CfgReadDWord(addr);\r
+ } \r
+\r
info->bus = bus;\r
info->slot = slot;\r
info->fcn = fcn;\r
- info->vendor = vendor;\r
- info->device = PCI_CfgReadWord(bus, slot, fcn, 0x0|2);\r
- info->revision = PCI_CfgReadWord(bus, slot, fcn, 0x8|0);\r
- info->oc = PCI_CfgReadWord(bus, slot, fcn, 0x8|2);\r
- \r
- // Load Config Bytes\r
- for(i=0;i<256/4;i++)\r
- {\r
- info->ConfigCache[i] = PCI_CfgReadDWord(bus, slot, fcn, i*4);\r
- }\r
+ info->vendor = vendor_dev & 0xFFFF;\r
+ info->device = vendor_dev >> 16;\r
+ tmp = info->ConfigCache[2];\r
+ info->revision = tmp & 0xFFFF;\r
+ info->oc = tmp >> 16;\r
\r
//#if LIST_DEVICES\r
//Log("BAR0 0x%08x BAR1 0x%08x BAR2 0x%08x", info->ConfigCache[4], info->ConfigCache[5], info->ConfigCache[6]);\r
/**
* \brief Clear the user's memory space back to the minimum required to run
*/
-extern tPAddr MM_ClearUser(void);
+extern void MM_ClearUser(void);
/**
* \brief Dump the address space to the debug channel
* \param Start First address