⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kernelbuspci.c

📁 上一个上传的有问题,这个是好的。visopsys包括系统内核和GUI的全部SOURCE code ,还包括一些基本的docs文档。里面src子目录对应所有SOURCE code.对于想研究操作系统的朋
💻 C
📖 第 1 页 / 共 2 页
字号:
		kernelProcessorOutPort32(CONFIG_PORT, address) ;			kernelProcessorOutPort32(DATA_PORT, data) ;		return (status = 0) ;}int kernelBusPCIGetBaseAddress(kernelBusPCIDevice * pciDevice, int baseAddressRegister, unsigned long * address, unsigned long * length, int * type){	int status = 0;		DWORD previousValue;		//Check if any of the given parameters is NULL		if(!pciDevice)	{#if defined(PCI_DEBUG)		kernelLog("kernelBusPCIGetBaseAddress: pciDevice == NULL\n");#endif		return (status = ERR_NULLPARAMETER);	}		if(!address)	{#if defined(PCI_DEBUG)		kernelLog("kernelBusPCIGetBaseAddress: address == NULL\n");#endif		return (status = ERR_NULLPARAMETER);	}		if(!length)	{#if defined(PCI_DEBUG)		kernelLog("kernelBusPCIGetBaseAddress: length == NULL\n");#endif		return (status = ERR_NULLPARAMETER);	}		if(!type)	{#if defined(PCI_DEBUG)		kernelLog("kernelBusPCIGetBaseAddress: type == NULL\n");#endif		return (status = ERR_NULLPARAMETER);	}		//Check if requested base address register is valid	if(baseAddressRegister < 0 || baseAddressRegister >= 256)	{#if defined(PCI_DEBUG)		kernelLog("kernelBusPCIGetBaseAddress: invalid baseAddressRegister %d requested\n", baseAddressRegister);#endif				return (status = ERR_BOUNDS);	}			//Zero all values	*address = 0;	*length = 0;	*type = -1;	//Check if this device header is type non-bridge	if(((*pciDevice).device.header_type & 0x7f) != 0)	{		//no, it is not. We cannot determine base address registers.		return (status = -1);	}		//Check if requested base address register is valid	if(baseAddressRegister < 0 || baseAddressRegister > 5)	{		return (status = -2);	}		*address = (*pciDevice).device.nonbridge.base_address[baseAddressRegister]; 		if(*address == 0)	{		return(status = -3);	}		//type is lowest bit of base address	*type = (int) (*address & 1);		if(type == PCI_MEMORY_ADDRESS)	{		*type = (int) (*address & 0x0f);				*address &= 0xfffffff0;	}	else	{		*address &= 0xfffffffe;	}		//Backup the BAR register value	kernelBusPCIReadConfig32((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 0x10 + baseAddressRegister * sizeof(DWORD), &previousValue);		//Okay, that's done. Now determine the length of the region by writing all bits 1 	//to this address field and reading the result out. The io/memory bit 1 is preserved!	kernelBusPCIWriteConfig32((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 0x10 + baseAddressRegister * sizeof(DWORD), 0xfffffffe | (*type & 1));		kernelBusPCIReadConfig32((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 0x10 + baseAddressRegister * sizeof(DWORD), length);		if((*type & 1) == PCI_IO_ADDRESS)		*length &= 0xfffffffc;	else		*length &= 0xfffffff0;		kernelBusPCIWriteConfig32((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 0x10 + baseAddressRegister * sizeof(DWORD), previousValue);		return (status = 0);}int kernelBusPCIEnable(kernelBusPCIDevice * pciDevice){//	WORD powerSettings;	WORD commandRegister;		int status;		if(!pciDevice)	{#if defined(PCI_DEBUG)		kernelLog("kernelBusPCIEnable: pciDevice == NULL\n");#endif		return (status = ERR_NULLPARAMETER);	}				//TODO: Activate the device if it was in power-save mode/*	kernelBusPCIReadConfig16((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 2, &powerSettings);		powerSettings |= 0x800;		kernelBusPCIWriteConfig16((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 2, powerSettings); */		//Activate IO and Memory IO	kernelBusPCIReadConfig16((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 3, &commandRegister);		commandRegister |= 3;		kernelBusPCIWriteConfig16((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 3, commandRegister);		return (status = 0);}int kernelBusPCIDisable(kernelBusPCIDevice * pciDevice){//	WORD powerSettings;	WORD commandRegister;		int status;		if(!pciDevice)	{#if defined(PCI_DEBUG)		kernelLog("kernelBusPCIDisable: pciDevice == NULL\n");#endif		return (status = ERR_NULLPARAMETER);	}		//TODO: Activate the device if it was in power-save mode/*	kernelBusPCIReadConfig16((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 2, &powerSettings);		powerSettings |= 0x800;		kernelBusPCIWriteConfig16((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 2, powerSettings); */		//Activate IO and Memory IO	kernelBusPCIReadConfig16((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 3, &commandRegister);		commandRegister &= 0xfffc;		kernelBusPCIWriteConfig16((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 3, commandRegister);		return (status = 0);}int kernelBusPCISetMaster(kernelBusPCIDevice * pciDevice){	//Sets the device to be busmaster -> transfers are quicker	WORD commandRegister;		BYTE latency;		int status;		if(!pciDevice)	{#if defined(PCI_DEBUG)		kernelLog("kernelBusPCISetMaster: pciDevice == NULL\n");#endif		return (status = ERR_NULLPARAMETER);	}		//Read current settings from command register	kernelBusPCIReadConfig16((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 2, &commandRegister);		//toggle busmaster-Bit on	commandRegister |= 4;		//write config back	kernelBusPCIWriteConfig16((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 2, commandRegister);		//Check latency timer	kernelBusPCIReadConfig8((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 13, &latency);		if(latency < 0x10) latency = 0x40;		kernelBusPCIWriteConfig8((*pciDevice).device.bus_nr, (*pciDevice).device.device_nr, (*pciDevice).device.function_nr, 13, latency);		return (status = 0);}		 		/*int kernelBusPCIGetDeviceName(WORD vendorID, WORD deviceID, int vendorLength, char * vendorName, int deviceLength, char * deviceName){//Gets a human readable name for a device id and vendor id   	int status;		fileStream pciIDList;		char * tmpString;		char idString[5];		WORD id;		//open the file with the Info(path is can be changed)	status = kernelFileStreamOpen("/system/pcilist.txt", OPENMODE_READ, &pciIDList);    	if(status < 0) 		return (status);			tmpString = (char *) kernelMalloc(MAX_CONFIG_LINE_LENGTH);		if(tmpString == NULL)		return (status = -2);		//find vendor ID	while(1)	{		status = kernelFileStreamReadLine(&pciIDList, MAX_CONFIG_LINE_LENGTH, tmpString);			if(status < 0) 			return (status);				//ignore comment lines and device lines		if(tmpString[0] != ';' && tmpString[0] != '\t')		{			idString[0] = tmpString[0];			idString[1] = tmpString[1];			idString[2] = tmpString[2];			idString[3] = tmpString[3];			idString[4] = '\0';						id = hexStringToInt(idString);						if(id == vendorID)			{					kernelLog(tmpString);				//status still holds the line length 				if(vendorLength > status - 5) vendorLength = status - 5;								//copy the vendorname string to its destination				kernelMemCopy((void *) &tmpString[5], (void *) vendorName, vendorLength - 1);								//terminate the string porperly				vendorName[vendorLength] = '\0';								break;			}		}	}		while(1)	{		status = kernelFileStreamReadLine(&pciIDList, MAX_CONFIG_LINE_LENGTH, tmpString);			if(status < 0) 			return (status);				//ignore comment lines		if(deviceName[0] != ';')		{			//if next vendor id is there device ID is not found			if(deviceName[0] != 't')			{				return (status = -1);			}						//Copy device id into seperate string			idString[0] = tmpString[1];			idString[1] = tmpString[2];			idString[2] = tmpString[3];			idString[3] = tmpString[4];			idString[4] = '\0';						id = hexStringToInt(idString);						if(id == deviceID)			{					//status still holds the line length 				if(deviceLength > status - 6) deviceLength = status - 6;								//copy the vendorname string to its destination				kernelMemCopy((void *) &tmpString[6], (void *) deviceName, deviceLength - 1);								//terminate the string porperly				deviceName[deviceLength] = '\0';								break;			}		}	}		kernelFree(tmpString);		return (status = 0);}	*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -