Configuring PCI Express

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
User avatar
hegde1997
Member
Member
Posts: 40
Joined: Mon Jan 30, 2012 7:36 am
Location: Bangalore, India
Contact:

Configuring PCI Express

Post by hegde1997 »

Please some one tell me what has to be done after mcfg is located.
Walking my way in making my OS
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: Configuring PCI Express

Post by Combuster »

Commit your code.



(Fix your question, please.)
"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 ]
User avatar
hegde1997
Member
Member
Posts: 40
Joined: Mon Jan 30, 2012 7:36 am
Location: Bangalore, India
Contact:

Re: Configuring PCI Express

Post by hegde1997 »

Combuster wrote:Commit your code.



(Fix your question, please.)
Actually my original post was this http://forum.osdev.org/viewtopic.php?f=1&t=26887
but i got no replies for weeks together so made a new post as i had no other way.

There are base address pointer structures located after mcfg table. But how should i know that how many such pointing structures are present ?

Code: Select all


 #define _pcie_base_addr_strct_size 16
 typedef struct pcie_confaddr_s
 {
	 uint64 *base_addr; //8 bytes base addr
	 uint16 seg_grp_num; //2 bytes segment group addr
	 uint8 bus_num_s; //stating bus number
	 uint8 bus_num_e; //ending bus number
	 uint32 reserved; //reserved
 }__attribute__((packed)) pcie_confaddr_t;

  typedef struct sdt_header_s
  {
	  char signature[4];
	  uint32 len;
	  uint8 revision;
	  uint8 checksum;
	  char OEMID[6];
	  char OEMtableID[8];
	  uint32 OEMrevision;
	  uint32 creatorID;
	  uint32 creatorRevision;
  }__attribute__((packed))sdt_header_t;


sdt_header_t *acpi_getsdt(char *sig)
{
	return acpi_findsdt(xsdt,sig);
}

sdt_header_t *acpi_findsdt(xsdt_t *_xsdt, char *signature)
{
	int i=0;sdt_header_t *tmp;
	for(i=0;i<22;i++)
	{
		tmp=(sdt_header_t *)_ptr_conv _xsdt->other_tables[i];
		if(strncmp(tmp->signature,signature,4)==0)
		  if(bytesum((phys_addr *)_ptr_conv tmp,tmp->len)==0)
		    return tmp;				
	}
	return (sdt_header_t *)0;
}


void pcie_init()
{
	sdt_header_t *mcfg=acpi_getsdt("MCFG");
	printf("\n\t Locating PCI Express Extended configuration space");
	if(!mcfg)
	{
		mcfg=mcfg_pci;
		if(!mcfg)
		{
			mprintf(error_text_colour,"\n\t Unable to locate PCI Express Extended configuration space");
			return;
		}		
	}
	if(((bytesum((phys_addr *) _ptr_conv mcfg,mcfg->len))&0xff)!=0)
	{		
		mcfg=mcfg_pci;
		if(!mcfg || (((bytesum((phys_addr *) _ptr_conv mcfg,mcfg->len))&0xff)!=0))
		{
			mprintf(error_text_colour,"\n\t Invalid ACPI MCFG Table");
			return;
		}
	}
	bus_range[0]=(pcie_confaddr_t *)mcfg+(mcfg->len);
	printf("\n\t Found buses from : %d-%d ,",bus_range[0]->bus_num_s,bus_range[0]->bus_num_e);
	pcie_find_bus_ranges(mcfg);
}
void pcie_find_bus_ranges(sdt_header_t *mcfg)
{
	int i=0;
	bus_range[0]=(pcie_confaddr_t *)mcfg+(mcfg->len);
	i=0;
	while(i<51)
	{
		++i;
		bus_range[i]=bus_range[0]+(_pcie_base_addr_strct_size*i);
		printf(" %d-%d ,",bus_range[i]->bus_num_s,bus_range[i]->bus_num_e);
	}
}
Walking my way in making my OS
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: Configuring PCI Express

Post by Combuster »

no replies for weeks
I hope you know the difference between singular and plural :wink:

This question could probably be answered by reading the manual. Your previous question would probably be answered by reading the manual and learning to debug. Both questions could probably also be answered by "You're trying an expert subject niche but you're not apparently able to deal with that level of challenge."
"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