/* 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;
}
}