VxWorks PCI configuration method

Source: Internet
Author: User

/* Surfconfpcidevice. C */

/*
* Function functions:
***********
* Find out the memory address of the PCI device of this type based on its vendor number, device number, and index number myindex.
* Maps the physical address of the first memory to the virtual address.
*
* Call an instance:
***********
* If there are four PCI devices of this type, the function is called four times. The index number ranges from 0 ~ 3, as follows:
For (myindex = 0; myindex <4; myindex ++)
{
Mystatus = surfconfpcidevice (vendorid, devid, myindex );
}
*/

/*
Modification history
--------------------
21aug03 and GHB add functions and call instructions.
*/

# Include <VxWorks. h>
# Include <stdio. h>
# Include <syslib. h>
# Include <stdlib. h>
# Include <config. h>

# Include <drv/PCI/pciconfiglib. h>
# Include <vmlib. h>

# Ifndef pci_dev_mmu_msk
# Define pci_dev_mmu_msk (~ (Vm_page_size-1)/* mask MMU page */
# Endif/* pci_dev_mmu_msk */

/* External function prototype */
Extern status sysmmumapadd
(
Void * address,
Uint length,
Uint initialstatemask,
Uint initialstate
);

/*************************************** **************************************** ***
* Surfconfpcidevice
*
* Find out the memory address of the PCI device of this type based on its vendor number, device number, and index number myindex.
* Maps the physical address of the first memory to the virtual address.
*
* Parameter:
* Vendorid: the vendor number of the PCI device.
* Devid: The device number of this type of PCI device
* Myindex: The index number of this type of PCI device
*
* Return:
* OK: the search and ing are successful.
* Error: the search or ing fails.
*
*/

Status surfconfpcidevice (INT vendorid, int devid, int myindex)
{
Int busno, devno, funcno;
Int membasecsr0, membasecsr1, iobasecsr;
Unsigned char IRQ;
Status mystatus;
 
/* Find the PCI device */
Mystatus = pcifinddevice (vendorid, devid, myindex,
(Int *) & busno, (int *) & devno, (int *) & funcno );

If (mystatus = OK)/* Find this type of PCI device */
{
Pciconfiginlong (busno, devno, funcno, pci_assist_base_address_0, & membasecsr0 );
Pciconfiginlong (busno, devno, funcno, pci_assist_base_address_1, & membasecsr1 );
Pciconfiginlong (busno, devno, funcno, pci_assist_base_address_2, & iobasecsr );
/* Pciconfiginbyte (busno, devno, funcno, pci_pai_dev_int_line, & IRQ );*/
Membasecsr0 = membasecsr0 &(~ 0x0000000f)/* pci_membase_mask */;
Membasecsr1 = membasecsr1 &(~ 0x0000000f)/* pci_membase_mask */;
/* Iobasecsr = iobasecsr & pci_iobase_mask ;*/

Printf ("\ nbusno = % d, devno = % d, funcno = % d, membasecsr0 = % x, membasecsr1 = % x, iobasecsr = % d \ n ",
Busno, devno, funcno, membasecsr0, membasecsr1, iobasecsr );

# Ifdef include_mmu_basic
If (sysmmumapadd (void *) (membasecsr0 & pci_dev_mmu_msk), 0x200000,
Vm_state_mask_valid | vm_state_mask_writable |
Vm_state_mask_cacheable,
Vm_state_valid | vm_state_writable |
Vm_state_cacheable_not) = Error)
{
Printf ("\ nghb_vram error \ n ");
Return Error;
};
# Endif/* include_mmu_basic */

/* The last parameter '| pci_assist_master_enable' seems dispensable, with no effect */
Pciconfigoutword (busno, devno, funcno,
Pci_cmd_command, pci_cmd_io_enable |
Pci_cmd_mem_enable | pci_cmd_master_enable );
Return OK;
}
Else
{
Printf ("\ nfind VRAM device error \ n ");
Return Error;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.