More documentation, mostly to the PCI
[tpg/acess2.git] / Kernel / drv / pci.c
index 59a7d77..9f1dd6e 100644 (file)
@@ -1,28 +1,32 @@
 /*\r
-AcessOS/AcessBasic v0.1\r
-PCI Bus Driver\r
-*/\r
-#include <common.h>\r
+ * AcessOS/AcessBasic v0.1\r
+ * PCI Bus Driver\r
+ */\r
+#define DEBUG  0\r
+#include <acess.h>\r
+#include <modules.h>\r
 #include <vfs.h>\r
 #include <fs_devfs.h>\r
 #include <drv_pci.h>\r
 \r
-#define DEBUG  0\r
 #define        LIST_DEVICES    1\r
 \r
 // === STRUCTURES ===\r
-typedef struct s_pciDevice {\r
+typedef struct sPCIDevice\r
+{\r
        Uint16  bus, slot, fcn;\r
        Uint16  vendor, device;\r
        union {\r
-               struct {Uint8 class, subclass;};\r
+               struct {\r
+                       Uint8 class, subclass;\r
+               };\r
                Uint16  oc;\r
        };\r
        Uint16  revision;\r
        Uint32  ConfigCache[256/4];\r
        char    Name[8];\r
        tVFS_Node       Node;\r
-} t_pciDevice;\r
+} tPCIDevice;\r
 \r
 // === CONSTANTS ===\r
 #define SPACE_STEP     5\r
@@ -45,7 +49,7 @@ Uint32        PCI_GetBAR4(int id);
 Uint32 PCI_GetBAR5(int id);\r
 Uint16 PCI_AssignPort(int id, int bar, int count);\r
 \r
- int   PCI_EnumDevice(Uint16 bus, Uint16 dev, Uint16 fcn, t_pciDevice *info);\r
+ int   PCI_EnumDevice(Uint16 bus, Uint16 dev, Uint16 fcn, tPCIDevice *info);\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
@@ -56,7 +60,7 @@ Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);
  int   giPCI_BusCount = 1;\r
  int   giPCI_InodeHandle = -1;\r
  int   giPCI_DeviceCount = 0;\r
-t_pciDevice    *gPCI_Devices = NULL;\r
+tPCIDevice     *gPCI_Devices = NULL;\r
 tDevFS_Driver  gPCI_DriverStruct = {\r
        NULL, "pci",\r
        {\r
@@ -79,7 +83,7 @@ int PCI_Install(char **Arguments)
 {\r
         int    bus, dev, fcn, i;\r
         int    space = 0;\r
-       t_pciDevice     devInfo;\r
+       tPCIDevice      devInfo;\r
        void    *tmpPtr = NULL;\r
        \r
        // Build Portmap\r
@@ -89,7 +93,6 @@ int PCI_Install(char **Arguments)
                gaPCI_PortBitmap[i] = -1;\r
        for( i = 0; i < MAX_RESERVED_PORT % 32; i ++ )\r
                gaPCI_PortBitmap[MAX_RESERVED_PORT / 32] = 1 << i;\r
-       //LogF("Done.\n");\r
        \r
        // Scan Busses\r
        for( bus = 0; bus < giPCI_BusCount; bus++ )\r
@@ -107,7 +110,7 @@ int PCI_Install(char **Arguments)
                                if(giPCI_DeviceCount == space)\r
                                {\r
                                        space += SPACE_STEP;\r
-                                       tmpPtr = realloc(gPCI_Devices, space*sizeof(t_pciDevice));\r
+                                       tmpPtr = realloc(gPCI_Devices, space*sizeof(tPCIDevice));\r
                                        if(tmpPtr == NULL)\r
                                                break;\r
                                        gPCI_Devices = tmpPtr;\r
@@ -121,7 +124,7 @@ int PCI_Install(char **Arguments)
                                        giPCI_BusCount++;\r
                                }\r
                                devInfo.Node.Inode = giPCI_DeviceCount;\r
-                               memcpy(&gPCI_Devices[giPCI_DeviceCount], &devInfo, sizeof(t_pciDevice));\r
+                               memcpy(&gPCI_Devices[giPCI_DeviceCount], &devInfo, sizeof(tPCIDevice));\r
                                giPCI_DeviceCount ++;\r
                                #if LIST_DEVICES\r
                                Log("[PCI ] Device %i,%i:%i => 0x%x:0x%x",\r
@@ -140,11 +143,14 @@ int PCI_Install(char **Arguments)
                if(tmpPtr != gPCI_Devices)\r
                        break;\r
        }\r
-       tmpPtr = realloc(gPCI_Devices, giPCI_DeviceCount*sizeof(t_pciDevice));\r
+       \r
+       if(giPCI_DeviceCount == 0)\r
+               return MODULE_ERR_NOTNEEDED;\r
+       \r
+       tmpPtr = realloc(gPCI_Devices, giPCI_DeviceCount*sizeof(tPCIDevice));\r
        if(tmpPtr == NULL)\r
-               return 0;\r
+               return MODULE_ERR_MALLOC;\r
        gPCI_Devices = tmpPtr;\r
-       //LogF("Done.\n");\r
        \r
        // Complete Driver Structure    \r
        gPCI_DriverStruct.RootNode.Size = giPCI_DeviceCount;\r
@@ -152,7 +158,7 @@ int PCI_Install(char **Arguments)
        // And add to DevFS\r
        DevFS_AddDevice(&gPCI_DriverStruct);\r
        \r
-       return 1;\r
+       return MODULE_ERR_OK;\r
 }\r
 \r
 /**\r
@@ -167,7 +173,7 @@ char *PCI_ReadDirRoot(tVFS_Node *Node, int Pos)
                return NULL;\r
        }\r
        \r
-       LEAVE('%s', gPCI_Devices[Pos].Name);\r
+       LEAVE('s', gPCI_Devices[Pos].Name);\r
        return strdup( gPCI_Devices[Pos].Name );\r
 }\r
 /**\r
@@ -366,7 +372,7 @@ Uint16 PCI_AssignPort(int id, int bar, int count)
        Uint16  portVals;\r
         int    gran=0;\r
         int    i, j;\r
-       t_pciDevice     *dev;\r
+       tPCIDevice      *dev;\r
        \r
        //LogF("PCI_AssignPort: (id=%i,bar=%i,count=%i)\n", id, bar, count);\r
        \r
@@ -423,9 +429,9 @@ Uint16 PCI_AssignPort(int id, int bar, int count)
 }\r
 \r
 /**\r
- * \fn int     PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, t_pciDevice *info)\r
+ * \fn int     PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info)\r
  */\r
-int    PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, t_pciDevice *info)\r
+int    PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info)\r
 {\r
        Uint16  vendor;\r
         int    i;\r
@@ -468,7 +474,7 @@ int PCI_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, t_pciDevice *info)
        info->Name[2] = '.';\r
        info->Name[3] = '0' + slot/10;\r
        info->Name[4] = '0' + slot%10;\r
-       info->Name[5] = '.';\r
+       info->Name[5] = ':';\r
        info->Name[6] = '0' + fcn;\r
        info->Name[7] = '\0';\r
        \r
@@ -553,9 +559,10 @@ Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)
 \r
 \r
 // === EXPORTS ===\r
-/*\r
+//*\r
 EXPORT(PCI_CountDevices);\r
 EXPORT(PCI_GetDevice);\r
+EXPORT(PCI_GetDeviceByClass);\r
 EXPORT(PCI_AssignPort);\r
 EXPORT(PCI_GetIRQ);\r
-*/\r
+//*/\r

UCC git Repository :: git.ucc.asn.au