Fixed the EnvP array passed to Proc_StartUser not being NULL terminated
[tpg/acess2.git] / Kernel / drv / pci.c
index 9f1dd6e..20eb932 100644 (file)
@@ -56,7 +56,7 @@ Uint16        PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);
 Uint8  PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
 \r
 // === GLOBALS ===\r
-//MODULE_DEFINE(0, 0x0100, PCI, PCI_Install, NULL);\r
+MODULE_DEFINE(0, 0x0100, PCI, PCI_Install, NULL, NULL);\r
  int   giPCI_BusCount = 1;\r
  int   giPCI_InodeHandle = -1;\r
  int   giPCI_DeviceCount = 0;\r
@@ -88,6 +88,10 @@ int PCI_Install(char **Arguments)
        \r
        // Build Portmap\r
        gaPCI_PortBitmap = malloc( 1 << 13 );\r
+       if( !gaPCI_PortBitmap ) {\r
+               Log_Error("PCI", "Unable to allocate %i bytes for bitmap", 1 << 13);\r
+               return MODULE_ERR_MALLOC;\r
+       }\r
        memset( gaPCI_PortBitmap, 0, 1 << 13 );\r
        for( i = 0; i < MAX_RESERVED_PORT / 32; i ++ )\r
                gaPCI_PortBitmap[i] = -1;\r
@@ -97,62 +101,64 @@ int PCI_Install(char **Arguments)
        // Scan Busses\r
        for( bus = 0; bus < giPCI_BusCount; bus++ )\r
        {\r
-               for( dev = 0; dev < 10; dev++ ) // 10 Devices per bus\r
+               for( dev = 0; dev < 32; dev++ ) // 32 Devices per bus\r
                {\r
-                       for( fcn = 0; fcn < 8; fcn++ )  // 8 functions per device\r
+                       for( fcn = 0; fcn < 8; fcn++ )  // Max 8 functions per device\r
                        {\r
                                // Check if the device/function exists\r
                                if(!PCI_EnumDevice(bus, dev, fcn, &devInfo))\r
-                               {\r
                                        continue;\r
-                               }\r
                                \r
                                if(giPCI_DeviceCount == space)\r
                                {\r
                                        space += SPACE_STEP;\r
                                        tmpPtr = realloc(gPCI_Devices, space*sizeof(tPCIDevice));\r
                                        if(tmpPtr == NULL)\r
-                                               break;\r
+                                               return MODULE_ERR_MALLOC;\r
                                        gPCI_Devices = tmpPtr;\r
                                }\r
                                if(devInfo.oc == PCI_OC_PCIBRIDGE)\r
                                {\r
                                        #if LIST_DEVICES\r
-                                       Log("[PCI ] Bridge @ %i,%i:%i (0x%x:0x%x)",\r
+                                       Log_Log("PCI", "Bridge @ %i,%i:%i (0x%x:0x%x)",\r
                                                bus, dev, fcn, devInfo.vendor, devInfo.device);\r
                                        #endif\r
                                        giPCI_BusCount++;\r
                                }\r
+                               else\r
+                               {\r
+                                       #if LIST_DEVICES\r
+                                       Log_Log("PCI", "Device %i,%i:%i %04x => 0x%04x:0x%04x",\r
+                                               bus, dev, fcn, devInfo.oc, devInfo.vendor, devInfo.device);\r
+                                       #endif\r
+                               }\r
+                               \r
                                devInfo.Node.Inode = giPCI_DeviceCount;\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
-                                       bus, dev, fcn, devInfo.vendor, devInfo.device);\r
-                               #endif\r
                                \r
                                // WTF is this for?\r
+                               // Maybe bit 23 must be set for the device to be valid?\r
+                               // - Actually, maybe 23 means that there are sub-functions\r
                                if(fcn == 0) {\r
                                        if( !(devInfo.ConfigCache[3] & 0x800000) )\r
                                                break;\r
                                }\r
                        }\r
-                       if(tmpPtr != gPCI_Devices)\r
-                               break;\r
                }\r
-               if(tmpPtr != gPCI_Devices)\r
-                       break;\r
        }\r
        \r
-       if(giPCI_DeviceCount == 0)\r
+       if(giPCI_DeviceCount == 0) {\r
+               Log_Notice("PCI", "No devices were found");\r
                return MODULE_ERR_NOTNEEDED;\r
+       }\r
        \r
        tmpPtr = realloc(gPCI_Devices, giPCI_DeviceCount*sizeof(tPCIDevice));\r
        if(tmpPtr == NULL)\r
                return MODULE_ERR_MALLOC;\r
        gPCI_Devices = tmpPtr;\r
        \r
-       // Complete Driver Structure    \r
+       // Complete Driver Structure\r
        gPCI_DriverStruct.RootNode.Size = giPCI_DeviceCount;\r
        \r
        // And add to DevFS\r
@@ -290,8 +296,8 @@ int PCI_GetDeviceByClass(Uint16 class, Uint16 mask, int prev)
        \r
        for( ; i < giPCI_DeviceCount; i++ )\r
        {\r
-               if((gPCI_Devices[i].oc & mask) != class)        continue;\r
-               return i;\r
+               if((gPCI_Devices[i].oc & mask) == class)\r
+                       return i;\r
        }\r
        return -1;\r
 }\r

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