📄 tmprocessor.c
字号:
/*
* +-------------------------------------------------------------------+
* | Copyright (c) 1995,2000 TriMedia Technologies Inc. |
* | |
* | This software is furnished under a license and may only be used |
* | and copied in accordance with the terms and conditions of such a |
* | license and with the inclusion of this copyright notice. This |
* | software or any other copies of this software may not be provided |
* | or otherwise made available to any other person. The ownership |
* | and title of this software is not transferred. |
* | |
* | The information in this software is subject to change without |
* | any prior notice and should not be construed as a commitment by |
* | TriMedia Technologies. |
* | |
* | This code and information is provided "as is" without any |
* | warranty of any kind, either expressed or implied, including but |
* | not limited to the implied warranties of merchantability and/or |
* | fitness for any particular purpose. |
* +-------------------------------------------------------------------+
*
*
* Module name : tmProcessor.c 1.21
*
* Last update : 2002-03-14
*
*
* Description :
*
*
*
*
* Revision :
*
* 2.0 1/ 6/98: Reading from PCI now, if possible.
* Dropped CTC support.
* 2.1 3/19/98: Fixed Bug # 501279
* 2.2 11/30/98: Support TM2.
* Fixed Bug # 502241
* 2.3 2/ 9/99 Support TM1300, # 502820
* 2.4 2/19/99 Disable XIO, # 502164
*
*/
#ifndef MAJOR_VERSION
#define MAJOR_VERSION 2
#endif
#ifndef MINOR_VERSION
#define MINOR_VERSION 4
#endif
#ifndef BUILD_VERSION
#define BUILD_VERSION 0
#endif
/*-----------------------------includes-------------------------------------*/
#include <tmlib/tmtypes.h>
#include <tm1/mmio.h>
#include <tm1/tmXIOmmio.h>
#include <tm1/tmProcessor.h>
#include <tm1/tmInterrupts.h>
/* From tmPCI.c */
#define CONFIG_TIMEOUT 1000
#define CONFIG_BUSY_BIT 0x01
#define CONFIG_DONE_BIT 0x02
static int pciConfigStatus (UInt32 bits, UInt32 zero_flag)
{
int timeout = 0;
unsigned biu_status, x;
while (timeout < CONFIG_TIMEOUT)
{
biu_status = MMIO(BIU_STATUS) ;
if ((biu_status & 0x100) != 0)
{
/*DP(("duplicate config bit set after busy wait\n")); */
}
x = (biu_status & bits);
if (zero_flag)
{
if (x == 0)
{
break;
}
}
else
{
if (x != 0)
{
break;
}
}
timeout++ ;
}
if (timeout >= CONFIG_TIMEOUT)
{
return 1;
}
else
{
return 0;
}
}
static tmLibdevErr_t
pciConfigRead(UInt32 address, UInt32* DataPointer )
{
int err;
unsigned long config_data ;
/*Check for config busy*/
err = pciConfigStatus (CONFIG_BUSY_BIT, True);
if (err)
{
return PCI_ERR_CONFIG_READ ;
}
/*Execute the read*/
MMIO(CONFIG_ADR) = address ;
MMIO(CONFIG_CTL) = 0x10 ; /* read cycle, all bytes */
/* Wait for config done*/
err = pciConfigStatus (CONFIG_DONE_BIT, False);
if (err)
{
return PCI_ERR_CONFIG_READ ;
}
/*Get the data*/
config_data = MMIO(CONFIG_DATA) ;
/*Reset config done bit*/
MMIO(BIU_STATUS) = 0x2 ;
/*Check for config ! busy and ! done*/
err = pciConfigStatus (CONFIG_DONE_BIT | CONFIG_BUSY_BIT, True);
if (err)
{
return PCI_ERR_CONFIG_READ ;
}
*DataPointer = config_data;
return TMLIBDEV_OK;
}
/* End From tmPCI.c */
extern UInt32 _clock_freq_init[];
extern UInt32 _node_number_init[];
extern UInt32 _number_of_nodes_init[];
extern UInt32 _host_type_init[];
#define CONFIG_TIMEOUT 1000
/*
* This is a TM2 reg that we need to distinguish different TM2's.
*/
#ifndef BLOCK_POWER_DOWN
#define BLOCK_POWER_DOWN (0x103428)
#endif
/*
* See BIU_STATUS in Figure 10-8 Databook
*/
#define CONFIG_BUSY_BIT 0x01
#define CONFIG_DONE_BIT 0x02
/*
* See Figure 10-2 Databook
*/
#define PCI_TM1000_ID 0x5400
#define PCI_TM2000_ID 0x5401
#define PCI_TM1300_ID 0x5402
#define PCI_PHILIPS_ID 0x1131
#define PCI_VENDOR_ID_TM 0x54001131
#define PCI_VENDOR_ID_TM_MASK 0xFFF0FFFF /* check only these bits */
#define DEVICE_ID_MASK 0xFFFF0000
#define DEVICE_ID_SHIFT 16
#define DEVICE_VENDOR_REG 0x0
#define REVISION_REG 0x08
#define DRAMBASE_REG 0x10
#define MMIOBASE_REG 0x14
static procCapabilities_t Capabilities =
{
{MAJOR_VERSION, MINOR_VERSION, BUILD_VERSION},
PROC_DEVICE_UNKNOWN,
PROC_REVISION_UNKNOWN,
(UInt32) _clock_freq_init,
(UInt32) _node_number_init,
(UInt32) _number_of_nodes_init,
(tmHostType_t) _host_type_init
};
/* ------------
* Check whether we are this pci_device by comparing unique addresses
*/
static Bool
my_sdram_n_mmio(UInt32 pci_device)
{
UInt32 dram_base, mmio_base;
/*
* Read SDRAM base and compare it with own
*/
if( pciConfigRead(pci_device | DRAMBASE_REG, &dram_base) != TMLIBDEV_OK ) {
return False;
}
if (dram_base != MMIO(DRAM_BASE)) {
return False;
}
/*
* Read MMIO base and compare it with own
*/
if( pciConfigRead(pci_device | MMIOBASE_REG, &mmio_base) != TMLIBDEV_OK ) {
return False;
}
if (mmio_base != MMIO(MMIO_BASE)) {
return False;
}
return True;
}
/* ------------
* Try to find information on the PCI bus about the processor we're
* running on. Return the DEVICE_ID, or 0 in case of error.
*/
static UInt32
find_info_on_pci(UInt32* pproc_info)
{
UInt32 i, cmd_status_val;
/*
* Go through all 21 devices and check whether we are there
*/
for (i = 1<<11; i != 0; i<<=1) {
if( pciConfigRead(i | DEVICE_VENDOR_REG, &cmd_status_val) != TMLIBDEV_OK ) {
continue; /* Read failed */
}
/* check vendor == Philips (0x1131) and device = TM (0x540_) */
if ((cmd_status_val & PCI_VENDOR_ID_TM_MASK) == PCI_VENDOR_ID_TM) {
if ( my_sdram_n_mmio(i) ) { /* found this TriMedia */
if ( pciConfigRead(i | REVISION_REG, pproc_info) != TMLIBDEV_OK ) {
return 0;
}
*pproc_info &= 0xff;
return (cmd_status_val & DEVICE_ID_MASK) >> DEVICE_ID_SHIFT;
}
}
}
return 0;
}
extern tmLibdevErr_t
procGetCapabilities(pprocCapabilities_t * cap)
{
UInt32 proc_info, found;
/*
* We only want to run this code once, so:
*/
if (Capabilities.deviceID == PROC_DEVICE_UNKNOWN) {
Capabilities.deviceID = PROC_DEVICE_TM1000;
/* default for now */
if (Capabilities.hostID == tmTmSimHost) {
/*
* We are running on the simulator
*/
if (MMIO(VO_STATUS) & 0x10) {
/*
* If we have EVO this must be a TM1100
*/
Capabilities.deviceID = PROC_DEVICE_TM1100;
Capabilities.revisionID = PROC_REVISION_UNKNOWN;
} else {
Capabilities.deviceID = PROC_DEVICE_TM1000;
Capabilities.revisionID = PROC_REVISION_1_1S;
}
} else { /* hostID != tmTmSimHost */
UInt32 xio_value = MMIO(XIO_CTL);
/* Make sure we do not read from XIO. */
xioDisableXIO_BUS;
found = find_info_on_pci(&proc_info);
MMIO(XIO_CTL) = xio_value;
if ( found ) {
/*
* Newer TMs can be detected via PCI
*/
UInt8 revision_id = (proc_info >> 4) & 3;
UInt8 metal = proc_info & 0xf;
switch (metal) {
case 0:
Capabilities.revisionID = PROC_REVISION_1_0;
break;
case 1:
Capabilities.revisionID = PROC_REVISION_1_1;
break;
case 2:
Capabilities.revisionID = PROC_REVISION_1_2;
break;
case 3:
Capabilities.revisionID = PROC_REVISION_1_3;
break;
case 4:
Capabilities.revisionID = PROC_REVISION_1_4;
break;
case 5:
Capabilities.revisionID = PROC_REVISION_1_5;
break;
default:
Capabilities.revisionID = PROC_REVISION_UNKNOWN;
}
switch (found) {
/************************** TM1x00 **************************/
case PCI_TM1000_ID:
if (revision_id == 1 && metal <= 1) {
/*
* TM1000 1.1S or 1.0S
*/
Capabilities.deviceID = PROC_DEVICE_TM1000;
Capabilities.revisionID = (procRevision_t)((Int)PROC_REVISION_1_0S + metal);
} else if (revision_id == 2) {
/*
* We found a TM1100
*/
Capabilities.deviceID = PROC_DEVICE_TM1100;
} else {
/*
* We found something unknown.
*/
Capabilities.deviceID = PROC_DEVICE_UNKNOWN;
}
break;
/************************** TM1x00 **************************/
case PCI_TM1300_ID:
switch (revision_id)
{
case 0:
if (metal == 3)
{
/*
* We found a PNX1300
*/
Capabilities.deviceID = PROC_DEVICE_PNX1300;
Capabilities.revisionID = PROC_REVISION_1_0;
}
else
{
/*
* We found a TM1300
*/
Capabilities.deviceID = PROC_DEVICE_TM1300;
}
break;
default:
Capabilities.deviceID = PROC_DEVICE_UNKNOWN;
break;
}
break;
/************************** TM2x00 **************************/
case PCI_TM2000_ID:
{
UInt32 product = MMIO(BLOCK_POWER_DOWN);
UInt32 major = (product & 0xc0000000) >> 30;
UInt32 minor = (product & 0x30000000) >> 28;
/* Switch on Major Product No. */
switch (major) {
case 0:
/* Switch on Minor Product No. */
switch (minor) {
case 0: /* HD-HD */
Capabilities.deviceID = PROC_DEVICE_TM2700;
break;
case 1: /* HD-SD */
Capabilities.deviceID = PROC_DEVICE_TM2600;
break;
case 2: /* Classic DTV */
Capabilities.deviceID = PROC_DEVICE_TM2500;
break;
case 3: /* DVB TV / SD-SD */
Capabilities.deviceID = PROC_DEVICE_TM2800;
break;
}
break;
default:
Capabilities.deviceID = PROC_DEVICE_UNKNOWN;
}
break;
}
/************************** unknown *************************/
default:
Capabilities.deviceID = PROC_DEVICE_UNKNOWN;
} /* switch (found) */
} else { /* ! found */
/*************old TM1000 or not working PCI *****************/
/*
* We may have a TM1000 1.1 (where PCI did not work properly),
* but maybe the PCI lines on the board are not connected properly
* (standalone JTAG board par example).
*/
if (Capabilities.hostID == tmNoHost) {
UInt32 ien, temp = MMIO(EVO_CLIP);
ien = intCLEAR_IEN();
MMIO(EVO_CLIP) = (~temp) >> 1;
if ( MMIO(EVO_CLIP) == (~temp) >> 1 ) {
Capabilities.deviceID = PROC_DEVICE_TM1100;
Capabilities.revisionID = PROC_REVISION_UNKNOWN;
} else {
Capabilities.deviceID = PROC_DEVICE_TM1000;
Capabilities.revisionID = PROC_REVISION_1_1S;
}
MMIO(EVO_CLIP) = temp;
intRESTORE_IEN(ien);
} else {
Capabilities.deviceID = PROC_DEVICE_TM1000;
Capabilities.revisionID = PROC_REVISION_1_1;
}
} /* found */
}
}
*cap = &Capabilities;
return TMLIBDEV_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -