BGA Adapter not showing up in PCI device list

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Gogeta70
Member
Member
Posts: 28
Joined: Thu Jun 06, 2013 11:15 am

BGA Adapter not showing up in PCI device list

Post by Gogeta70 »

So i'm trying to set up the BGA for a 800 x 600 24bpp video mode. I'm able to get it to go into an 800x600 resolution (and i assume 24bpp), but i can't get the linear frame buffer address. On the wiki, it says i have to get BAR 0 of PCI device 0x1234 vendor 0x1111. So, upon enumerating the PCI devices, all i find is this:

Code: Select all

Initializing Bochs Graphics Adapter...

Bochs Graphics Adaptor detected.
Setting Video mode...
PCI Data: 12378086 Config address used: 80000000
PCI Data: 70008086 Config address used: 80000800
I know the adapter is there, so why won't it show up on the list of PCI devices?

Here is the code for the BGA driver and pci list:

Code: Select all

void bgaInit()
{
	printf("Initializing Bochs Graphics Adapter...\n\n");
	
	//To write an index/data pair to one of the BGA registers, first write its index value to the 16-bit IO-port VBE_DISPI_IOPORT_INDEX (0x01CE), followed by writing the data value to the 16-bit IO-port VBE_DISPI_IOPORT_DATA (0x01CF).
	
	outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ID);
	
	unsigned short bga_avail = 0;
	bga_avail = inw(VBE_DISPI_IOPORT_DATA);
	
	if(bga_avail < 0xB0C4)
	{
		printf("You are using an outdated version of the Bochs VGA Bios or are not using a VM with BGA. Please download the latest version of Bochs, or the latest Bochs VGA Bios.\n");
		return;
		
	} else {
		
		printf("Bochs Graphics Adaptor detected.\nSetting Video mode...\n");
	}
	
	outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ENABLE);
	outw(VBE_DISPI_IOPORT_DATA, VBE_DISPI_DISABLED);
	
	outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_XRES);
	outw(VBE_DISPI_IOPORT_DATA, 800);
	
	outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_YRES);
	outw(VBE_DISPI_IOPORT_DATA, 600);
	
	outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_BPP);
	outw(VBE_DISPI_IOPORT_DATA, VBE_DISPI_BPP_24);
	
	//outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ENABLE);
	//outw(VBE_DISPI_IOPORT_DATA, VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED);
	
	
	unsigned long bus = 0, device = 0;
	
	for(; bus < 256; bus++)
	{
		for(device = 0; device < 32; device++)
		{
			unsigned long pci_addr = 0x80000000 | (bus << 16) | (device << 11);
			outd(0xCF8, pci_addr);
			
			unsigned long pci_data = ind(0xCFC);
			
			if((pci_data & 0xFFFF) != 0xFFFF)
				printf("PCI Data: %.8X Config address used: %.8X\n", pci_data, pci_addr);
			
			unsigned long pci_hdr = pci_addr | ((0x0C & 0x3F)<< 2);
			
			outd(0xCF8, pci_hdr);
			unsigned long header_type = ind(0xCFC);
			
			header_type = (header_type >> 16) & 0x80;
			
			if(header_type != 0)
			{
				for(unsigned long i = 1; i < 8; i++)
				{
					unsigned long pci_id = pci_addr | ((i * 7) << 7);
					outd(0xCF8, pci_id);
					
					pci_data = ind(0xCFC);
					
					if((pci_data & 0xFFFF) == 0xFFFF)
						break;
					
					printf("  PCI Data: %.8X Config address used: %.8X\n", pci_data, pci_id);
				}
			}
		}
	}
}
Last edited by Gogeta70 on Thu Sep 05, 2013 10:46 pm, edited 1 time in total.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: BGA Adapter not showing up in PCI device list

Post by thepowersgang »

(First, I'd suggest moving that PCI code into a common functon)

You'll want to also check other functions, and make sure that bochs is configured to expose the adapter on PCI

e.g. (in bochsrc)

Code: Select all

pci: enabled=1, chipset=i440fx, slot1=pcivga
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Gogeta70
Member
Member
Posts: 28
Joined: Thu Jun 06, 2013 11:15 am

Re: BGA Adapter not showing up in PCI device list

Post by Gogeta70 »

I updated the PCI enumeration code in the first post to what i have now. I also made those changes to bochsrc, and now i'm seeing the BGA in bochs, but not in virtualbox. I thought virtualbox supported the BGA? I know it works in banked mode in virtualbox, as i made the top 20 lines red using banked mode. Banked mode is a very slow way of drawing the screen though, so i'd like to use a linear frame buffer.

This is what i'm getting:
Image
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: BGA Adapter not showing up in PCI device list

Post by Combuster »

It would help if you looked up the IDs printed, because the graphics device is actually listed

Also, the BGA is originally an ISA-style interface. It doesn't need a corresponding PCI device, and it can be attached as an hidden interface to the device that is listed - like it might happen with an emulated Cirrus Logic entry.

Or, even better, search before posting :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Gogeta70
Member
Member
Posts: 28
Joined: Thu Jun 06, 2013 11:15 am

Re: BGA Adapter not showing up in PCI device list

Post by Gogeta70 »

Well, you are certainly right. It was staring me in the face this whole time. ^_^

Ok, so i tried pulling the LFB address from BAR 0, but i'm getting 0x00000000 returned from it in both Bochs and VirtualBox... what am i doing wrong now?

Code: Select all

                                          // bus      // slot     // func       // register
	unsigned long pci_addr = 0x80000000 | (0 << 16) | (2 << 11) | (0 << 8) | ((0x10 & 0x3f) << 2);
	outd(0xCF8, pci_addr);
	unsigned long BAR = ind(0xCFC);
	
	printf("BAR 0: %.8X\n", BAR);
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: BGA Adapter not showing up in PCI device list

Post by Combuster »

Compare your code with how PCI really works.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply