emulation/qemu-i440fx: use fw_cfg_dma for fw_cfg_read
- configure DMA fw_cfg - add support to read using fw_cfg_dma - provide fw config version id info in logs BUG=N/A TEST=Build and boot using qemu-i440fx. Change-Id: I0be5355b124af40aba62c0840790d46ed0fe80a2 Signed-off-by: Himanshu Sahdev <himanshusah@hcl.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/35365 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Patrick Rudolph <siro@das-labor.org>
This commit is contained in:
		
				
					committed by
					
						 Patrick Georgi
						Patrick Georgi
					
				
			
			
				
	
			
			
			
						parent
						
							df02f7aed8
						
					
				
				
					commit
					8dc95ddbd4
				
			| @@ -24,20 +24,29 @@ | ||||
|  | ||||
| #define FW_CFG_PORT_CTL       0x0510 | ||||
| #define FW_CFG_PORT_DATA      0x0511 | ||||
| #define FW_CFG_DMA_ADDR_HIGH  0x0514 | ||||
| #define FW_CFG_DMA_ADDR_LOW   0x0518 | ||||
|  | ||||
| static int fw_cfg_detected; | ||||
| static uint8_t fw_ver; | ||||
|  | ||||
| static void fw_cfg_dma(int control, void *buf, int len); | ||||
|  | ||||
| static int fw_cfg_present(void) | ||||
| { | ||||
| 	static const char qsig[] = "QEMU"; | ||||
| 	unsigned char sig[4]; | ||||
| 	unsigned char sig[FW_CFG_SIG_SIZE]; | ||||
| 	int detected = 0; | ||||
|  | ||||
| 	if (fw_cfg_detected == 0) { | ||||
| 		fw_cfg_get(FW_CFG_SIGNATURE, sig, sizeof(sig)); | ||||
| 		detected = memcmp(sig, qsig, 4) == 0; | ||||
| 		detected = memcmp(sig, qsig, FW_CFG_SIG_SIZE) == 0; | ||||
| 		printk(BIOS_INFO, "QEMU: firmware config interface %s\n", | ||||
| 				detected ? "detected" : "not found"); | ||||
| 		if (detected) { | ||||
| 			fw_cfg_get(FW_CFG_ID, &fw_ver, sizeof(fw_ver)); | ||||
| 			printk(BIOS_INFO, "Firmware config version id: %d\n", fw_ver); | ||||
| 		} | ||||
| 		fw_cfg_detected = detected + 1; | ||||
| 	} | ||||
| 	return fw_cfg_detected - 1; | ||||
| @@ -50,6 +59,9 @@ static void fw_cfg_select(uint16_t entry) | ||||
|  | ||||
| static void fw_cfg_read(void *dst, int dstlen) | ||||
| { | ||||
| 	if (fw_ver & FW_CFG_VERSION_DMA) | ||||
| 		fw_cfg_dma(FW_CFG_DMA_CTL_READ, dst, dstlen); | ||||
| 	else | ||||
| 		insb(FW_CFG_PORT_DATA, dst, dstlen); | ||||
| } | ||||
|  | ||||
| @@ -500,3 +512,31 @@ void smbios_system_set_uuid(u8 *uuid) | ||||
| 	fw_cfg_smbios_init(); | ||||
| 	memcpy(uuid, type1_uuid, 16); | ||||
| } | ||||
|  | ||||
| /* | ||||
|  * Configure DMA setup | ||||
|  */ | ||||
|  | ||||
| static void fw_cfg_dma(int control, void *buf, int len) | ||||
| { | ||||
| 	volatile FwCfgDmaAccess dma; | ||||
| 	uintptr_t dma_desc_addr; | ||||
| 	uint32_t dma_desc_addr_hi, dma_desc_addr_lo; | ||||
|  | ||||
| 	dma.control = be32_to_cpu(control); | ||||
| 	dma.length  = be32_to_cpu(len); | ||||
| 	dma.address = be64_to_cpu((uintptr_t)buf); | ||||
|  | ||||
| 	dma_desc_addr = (uintptr_t)&dma; | ||||
| 	dma_desc_addr_lo = (uint32_t)(dma_desc_addr & 0xFFFFFFFFU); | ||||
| 	dma_desc_addr_hi = sizeof(uintptr_t) > sizeof(uint32_t) | ||||
| 				? (uint32_t)(dma_desc_addr >> 32) : 0; | ||||
|  | ||||
| 	// Skip writing high half if unnecessary. | ||||
| 	if (dma_desc_addr_hi) | ||||
| 		outl(be32_to_cpu(dma_desc_addr_hi), FW_CFG_DMA_ADDR_HIGH); | ||||
| 	outl(be32_to_cpu(dma_desc_addr_lo), FW_CFG_DMA_ADDR_LOW); | ||||
|  | ||||
| 	while (be32_to_cpu(dma.control) & ~FW_CFG_DMA_CTL_ERROR) | ||||
| 		; | ||||
| } | ||||
|   | ||||
| @@ -67,11 +67,20 @@ enum fw_cfg_enum { | ||||
|  | ||||
| #define FW_CFG_INVALID          0xffff | ||||
|  | ||||
| /* width in bytes of fw_cfg control register */ | ||||
| #define FW_CFG_CTL_SIZE         0x02 | ||||
|  | ||||
| /* fw_cfg "file name" is up to 56 characters (including terminating nul) */ | ||||
| #define FW_CFG_MAX_FILE_PATH    56 | ||||
|  | ||||
| /* size in bytes of fw_cfg signature */ | ||||
| #define FW_CFG_SIG_SIZE         4 | ||||
|  | ||||
| typedef struct FWCfgFile { | ||||
|     uint32_t  size;        /* file size */ | ||||
|     uint16_t  select;      /* write this to 0x510 to read it */ | ||||
|     uint16_t  reserved; | ||||
|     char      name[56]; | ||||
|     char      name[FW_CFG_MAX_FILE_PATH]; | ||||
| } FWCfgFile; | ||||
|  | ||||
| typedef struct FWCfgFiles { | ||||
| @@ -96,4 +105,26 @@ typedef struct FwCfgSmbios { | ||||
| 	uint16_t fieldoffset; | ||||
| } FwCfgSmbios; | ||||
|  | ||||
| /* FW_CFG_ID bits */ | ||||
| #define FW_CFG_VERSION          0x01 | ||||
| #define FW_CFG_VERSION_DMA      0x02 | ||||
|  | ||||
| /* FW_CFG_DMA_CONTROL bits */ | ||||
| #define FW_CFG_DMA_CTL_ERROR    0x01 | ||||
| #define FW_CFG_DMA_CTL_READ     0x02 | ||||
| #define FW_CFG_DMA_CTL_SKIP     0x04 | ||||
| #define FW_CFG_DMA_CTL_SELECT   0x08 | ||||
| #define FW_CFG_DMA_CTL_WRITE    0x10 | ||||
|  | ||||
| #define FW_CFG_DMA_SIGNATURE    0x51454d5520434647ULL /* "QEMU CFG" */ | ||||
|  | ||||
| /* Control as first field allows for different structures selected by this | ||||
|  * field, which might be useful in the future | ||||
|  */ | ||||
| typedef struct FwCfgDmaAccess { | ||||
| 	uint32_t control; | ||||
| 	uint32_t length; | ||||
| 	uint64_t address; | ||||
| } FwCfgDmaAccess; | ||||
|  | ||||
| #endif /* FW_CFG_IF_H */ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user