void pci_read_config(bdf_addr_t address, uint32_t *confmem) { unsigned loop; if (!confmem) { return; } address &= PCI_CONFIG_BDF_MASK; address |= (1<<31); out_dword(PCI_CONFIG_ADDRESS, address); confmem[0] = in_dword(PCI_CONFIG_DATA); /* * there is no such thing as a VendorID equal to 0xFFFF, * nor a DeviceID equal to 0xFFFF. * So it means the device is not present. * fill the buffer with 0xFF to stay on the safe side. */ if (0xFFFFFFFFUL == confmem[0]) { memset(confmem + 1, 0xFF, sizeof(confmem)-4); return; } address += 4; for (loop = 1; loop < PCI_HEADER_SIZE_REGS; loop++, address+=4) { out_dword(PCI_CONFIG_ADDRESS, address); confmem[loop] = in_dword(PCI_CONFIG_DATA); } }
BOOL pci_bus_check() { unsigned tmp; BOOL retcode = FALSE; out_byte(PCI_CONFIG_ADDRESS + 3, 1); tmp = in_dword(PCI_CONFIG_ADDRESS); out_dword(PCI_CONFIG_ADDRESS, (unsigned)(1<<31)); if (in_dword(PCI_CONFIG_ADDRESS) == (unsigned)(1<<31)) { retcode = TRUE; } out_dword(PCI_CONFIG_ADDRESS, tmp); return (retcode); }
void pci_read_config_reg32(bdf_addr_t address, unsigned offset, uint32_t *value) { if (!value) { return; } pci_config_space_set_addr(address, offset); *value = in_dword(PCI_CONFIG_DATA); }
PRIVATE void init_dma() { PCI dma[8]; int i,j; printl("Getting BUS :0 DEV:0 FUNC: 0\n"); u32* tmp=(u32*)&dma[0]; for(i=0;i<PCI_FUNC_NR;i++) { u32* tmp=(u32*)&dma[i]; for(j=0;j<PCI_REG_NR;j++) { out_dword(PCI_CONF_ADDR,MAKE_PCI_CONF(0,0,i,j)); tmp[j]=in_dword(PCI_CONF_DATA); } if(i==0) { //break; if(!(dma[0].conf_head&0x80)) { break; } } } tmp=(u32*)&dma[0]; for(i=0;i<16;i++) { printf("%d: %x\n",i,tmp[i]); } printl("BUS :0 DEV:0 FUNC: 0\n"); printl("BASE_TYPE:%x \nSUB_TYPE:%x\n",dma[0].base_type,dma[0].sub_type); }
// Load a 256 gray-scale uncompressed TIF image into the global array IMAGE int Load_gray256tif(BOOL Upright) { /* Load a tif imagefile. The image is loaded by rows into the global array IMAGE: - IMAGE_X and IMAGE_Y are the width and the height of the image respectively. - The generic pixel [x,y], where x=0..IMAGE_X-1 and y=0..IMAGE_Y-1, can be accessed as IMAGE[y*IMAGE_X+x] */ FILE* fp = imagefile; DWORD ifd_offset; WORD directory_entry_count; WORD offset; DWORD strip_offset, data_offset; BOOL strip_based = FALSE; BYTE* pimage; int i; if (fread(buffer,8,1,fp)!=1) return 1; if (in_word(0)!=0x4949) return 2; if (in_word(2)!=0x002a) return 3; ifd_offset = in_dword(4); if (fseek(fp,ifd_offset,SEEK_SET)) return 1; if (fread(buffer,2,1,fp)!=1) return 1; directory_entry_count=in_word(0); if (fread(buffer,directory_entry_count*12,1,fp)!=1) return 1; offset = 0; while (directory_entry_count > 0) { switch (in_word(offset)) { case 0x00fe: if (in_word(offset+8) != 0) return 4; break; case 0x0100: IMAGE_X = in_word(offset+8); break; case 0x0101: IMAGE_Y = in_word(offset+8); break; case 0x0102: if (in_word(offset+8) != 8) return 5; break; case 0x0103: if (in_word(offset+8) != 1) return 6; break; case 0x0106: if (in_word(offset+8) != 1) return 7; break; case 0x0111: strip_offset = in_word(offset+8); break; case 0x0115: if (in_word(offset+8) != 1) return 8; break; case 0x0116: if (in_word(offset+8) != IMAGE_Y) strip_based=TRUE; break; case 0x011c: if (in_word(offset+8) != 1) return 11; break; } offset += 12; -- directory_entry_count; } if (strip_based) { if (fseek(fp, strip_offset, SEEK_SET)) return 1; if (fread(buffer, 4, 1, fp) != 1) return 1; data_offset = in_dword(0); } else data_offset = strip_offset; HEAD_SIZE = data_offset; if( fseek(fp, 0, SEEK_SET) ) return 1; if( fread(FILE_HEAD, HEAD_SIZE, 1, fp) != 1 ) return 1; if( fseek(fp, data_offset, SEEK_SET) ) return 1; if (Upright) { pimage = IMAGE; for (i=0; i<IMAGE_Y; ++i) { if( fread(pimage, IMAGE_X, 1, fp) != 1 ) return 1; pimage += IMAGE_X; } } else { pimage = IMAGE + IMAGE_X*(IMAGE_Y-1); for (i=0; i<IMAGE_Y; ++i) { if( fread(pimage, IMAGE_X, 1, fp) != 1 ) return 1; pimage -= IMAGE_X; } } return 0; }