summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
0 files changed, 0 insertions, 0 deletions
ref='#n40'>40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
/* PCI.c - PCI functions */

/* Copyright - Galileo technology. */

#include <common.h>
#include <pci.h>

#include <galileo/pci.h>

static const unsigned char pci_irq_swizzle[2][PCI_MAX_DEVICES] = {
#ifdef CONFIG_ZUMA_V2
    {0,0,0,0,0,0,0,29, [8 ... PCI_MAX_DEVICES-1]=0},
    {0,0,0,0,0,0,0,28, [8 ... PCI_MAX_DEVICES-1]=0}
#else	/* EVB??? This is a guess */
    {0,0,0,0,0,0,0,27,27, [9 ... PCI_MAX_DEVICES-1]=0},
    {0,0,0,0,0,0,0,29,29, [9 ... PCI_MAX_DEVICES-1]=0}
#endif
};

static const unsigned int pci_p2p_configuration_reg[]={
    PCI_0P2P_CONFIGURATION, PCI_1P2P_CONFIGURATION};

static const unsigned int pci_configuration_address[]={
    PCI_0CONFIGURATION_ADDRESS, PCI_1CONFIGURATION_ADDRESS};

static const unsigned int pci_configuration_data[]={
    PCI_0CONFIGURATION_DATA_VIRTUAL_REGISTER,
    PCI_1CONFIGURATION_DATA_VIRTUAL_REGISTER};

static const unsigned int pci_error_cause_reg[]={
    PCI_0ERROR_CAUSE, PCI_1ERROR_CAUSE};

static const unsigned int pci_arbiter_control[]={
    PCI_0ARBITER_CONTROL, PCI_1ARBITER_CONTROL};

static const unsigned int pci_snoop_control_base_0_low[]={
    PCI_0SNOOP_CONTROL_BASE_0_LOW, PCI_1SNOOP_CONTROL_BASE_0_LOW};
static const unsigned int pci_snoop_control_top_0[]={
    PCI_0SNOOP_CONTROL_TOP_0, PCI_1SNOOP_CONTROL_TOP_0};

static const unsigned int pci_access_control_base_0_low[]={
    PCI_0ACCESS_CONTROL_BASE_0_LOW, PCI_1ACCESS_CONTROL_BASE_0_LOW};
static const unsigned int pci_access_control_top_0[]={
    PCI_0ACCESS_CONTROL_TOP_0, PCI_1ACCESS_CONTROL_TOP_0};

static const unsigned int pci_scs_bank_size[2][4] = {
    {PCI_0SCS_0_BANK_SIZE, PCI_0SCS_1_BANK_SIZE,
     PCI_0SCS_2_BANK_SIZE, PCI_0SCS_3_BANK_SIZE},
    {PCI_1SCS_0_BANK_SIZE, PCI_1SCS_1_BANK_SIZE,
     PCI_1SCS_2_BANK_SIZE, PCI_1SCS_3_BANK_SIZE}};

static const unsigned int pci_p2p_configuration[] = {
    PCI_0P2P_CONFIGURATION, PCI_1P2P_CONFIGURATION};

static unsigned int local_buses[] = { 0, 0};
/********************************************************************
* pciWriteConfigReg - Write to a PCI configuration register
*                    - Make sure the GT is configured as a master before writing
*                      to another device on the PCI.
*                    - The function takes care of Big/Little endian conversion.
*
*
* Inputs:   unsigned int regOffset: The register offset as it apears in the GT spec
*                   (or any other PCI device spec)
*           pciDevNum: The device number needs to be addressed.
*
*  Configuration Address 0xCF8:
*
*       31 30    24 23  16 15  11 10     8 7      2  0     <=bit Number
*  |congif|Reserved|  Bus |Device|Function|Register|00|
*  |Enable|        |Number|Number| Number | Number |  |    <=field Name
*
*********************************************************************/
void pciWriteConfigReg(PCI_HOST host, unsigned int regOffset,unsigned int pciDevNum,unsigned int data)
{
    volatile unsigned int DataForAddrReg;
    unsigned int functionNum;
    unsigned int busNum = PCI_BUS(pciDevNum);
    unsigned int addr;

    if(pciDevNum > 32) /* illegal device Number */
        return;
    if(pciDevNum == SELF) /* configure our configuration space. */
    {
        pciDevNum = (GTREGREAD(pci_p2p_configuration_reg[host]) >> 24) & 0x1f;
        busNum = GTREGREAD(pci_p2p_configuration_reg[host]) & 0xff0000;
    }
    functionNum =  regOffset & 0x00000700;
    pciDevNum = pciDevNum << 11;
    regOffset = regOffset & 0xfc;
    DataForAddrReg = ( regOffset | pciDevNum | functionNum | busNum) | BIT31;
    GT_REG_WRITE(pci_configuration_address[host],DataForAddrReg);
    GT_REG_READ(pci_configuration_address[host], &addr);
    if (addr != DataForAddrReg) return;
    GT_REG_WRITE(pci_configuration_data[host],data);
}

/********************************************************************
* pciReadConfigReg  - Read from a PCI0 configuration register
*                    - Make sure the GT is configured as a master before reading
*                     from another device on the PCI.
*                   - The function takes care of Big/Little endian conversion.
* INPUTS:   regOffset: The register offset as it apears in the GT spec (or PCI
*                        spec)
*           pciDevNum: The device number needs to be addressed.
* RETURNS: data , if the data == 0xffffffff check the master abort bit in the
*                 cause register to make sure the data is valid
*
*  Configuration Address 0xCF8:
*
*       31 30    24 23  16 15  11 10     8 7      2  0     <=bit Number
*  |congif|Reserved|  Bus |Device|Function|Register|00|
*  |Enable|        |Number|Number| Number | Number |  |    <=field Name
*
*********************************************************************/
unsigned int pciReadConfigReg (PCI_HOST host, unsigned int regOffset,unsigned int pciDevNum)
{
    volatile unsigned int DataForAddrReg;
   	unsigned int data;
    unsigned int functionNum;
    unsigned int busNum = PCI_BUS(pciDevNum);

    if(pciDevNum > 32) /* illegal device Number */
        return 0xffffffff;
    if(pciDevNum == SELF) /* configure our configuration space. */
    {
        pciDevNum = (GTREGREAD(pci_p2p_configuration_reg[host]) >> 24) & 0x1f;
        busNum = GTREGREAD(pci_p2p_configuration_reg[host]) & 0xff0000;
    }
    functionNum = regOffset & 0x00000700;
    pciDevNum = pciDevNum << 11;
    regOffset = regOffset & 0xfc;
    DataForAddrReg = (regOffset | pciDevNum | functionNum | busNum) | BIT31 ;
    GT_REG_WRITE(pci_configuration_address[host],DataForAddrReg);
    GT_REG_READ(pci_configuration_address[host], &data);
    if (data != DataForAddrReg)
        return 0xffffffff;
    GT_REG_READ(pci_configuration_data[host], &data);
    return data;
}

/********************************************************************
* pciOverBridgeWriteConfigReg - Write to a PCI configuration register where
*                               the agent is placed on another Bus. For more
*                               information read P2P in the PCI spec.
*
* Inputs:   unsigned int regOffset - The register offset as it apears in the
*           GT spec (or any other PCI device spec).
*           unsigned int pciDevNum - The device number needs to be addressed.
*           unsigned int busNum - On which bus does the Target agent connect
*                                 to.
*           unsigned int data - data to be written.
*
*  Configuration Address 0xCF8:
*
*       31 30    24 23  16 15  11 10     8 7      2  0     <=bit Number
*  |congif|Reserved|  Bus |Device|Function|Register|01|
*  |Enable|        |Number|Number| Number | Number |  |    <=field Name
*
*  The configuration Address is configure as type-I (bits[1:0] = '01') due to
*   PCI spec referring to P2P.
*
*********************************************************************/
void pciOverBridgeWriteConfigReg(PCI_HOST host,
				 unsigned int regOffset,
                                 unsigned int pciDevNum,
                                 unsigned int busNum,unsigned int data)
{
   	unsigned int   DataForReg;
    unsigned int   functionNum;

   	functionNum =  regOffset & 0x00000700;
    pciDevNum = pciDevNum << 11;
    regOffset = regOffset & 0xff;
    busNum = busNum << 16;
    if(pciDevNum == SELF) /* This board */
    {
        DataForReg = ( regOffset | pciDevNum | functionNum) | BIT0;
    }
    else
    {
        DataForReg = ( regOffset | pciDevNum | functionNum | busNum) |
            BIT31 | BIT0;
    }
    GT_REG_WRITE(pci_configuration_address[host],DataForReg);
    if(pciDevNum == SELF) /* This board */
    {
        GT_REG_WRITE(pci_configuration_data[host],data);
    }
    else /* configuration Transaction over the pci. */
    {
        /* The PCI is working in LE Mode So it swap the Data. */
        GT_REG_WRITE(pci_configuration_data[host],WORD_SWAP(data));
    }
}


/********************************************************************
* pciOverBridgeReadConfigReg  - Read from a PCIn configuration register where
*                               the agent target locate on another PCI bus.
*                             - Make sure the GT is configured as a master
*                               before reading from another device on the PCI.
*                             - The function takes care of Big/Little endian
*                               conversion.
* INPUTS:   regOffset: The register offset as it apears in the GT spec (or PCI
*                        spec). (configuration register offset.)
*           pciDevNum: The device number needs to be addressed.
*           busNum: the Bus number where the agent is place.
* RETURNS: data , if the data == 0xffffffff check the master abort bit in the
*                 cause register to make sure the data is valid
*
*  Configuration Address 0xCF8:
*
*       31 30    24 23  16 15  11 10     8 7      2  0     <=bit Number
*  |congif|Reserved|  Bus |Device|Function|Register|01|
*  |Enable|        |Number|Number| Number | Number |  |    <=field Name
*
*********************************************************************/
unsigned int pciOverBridgeReadConfigReg(PCI_HOST host,
					unsigned int regOffset,
                                        unsigned int pciDevNum,
                                        unsigned int busNum)
{
    unsigned int DataForReg;
    unsigned int data;
    unsigned int functionNum;

    functionNum = regOffset & 0x00000700;
    pciDevNum = pciDevNum << 11;
    regOffset = regOffset & 0xff;
    busNum = busNum << 16;
    if (pciDevNum == SELF) /* This board */
    {
        DataForReg = (regOffset | pciDevNum | functionNum) | BIT31 ;
    }
    else /* agent on another bus */
    {
        DataForReg = (regOffset | pciDevNum | functionNum | busNum) |
        BIT0 | BIT31 ;
    }
    GT_REG_WRITE(pci_configuration_address[host],DataForReg);
    if (pciDevNum == SELF) /* This board */
   	{
        GT_REG_READ(pci_configuration_data[host], &data);
    	return data;
    }
    else /* The PCI is working in LE Mode So it swap the Data. */
    {
        GT_REG_READ(pci_configuration_data[host], &data);
    	return WORD_SWAP(data);
    }
}

/********************************************************************
* pciGetRegOffset - Gets the register offset for this region config.
*
* INPUT:   Bus, Region - The bus and region we ask for its base address.
* OUTPUT:   N/A
* RETURNS: PCI register base address
*********************************************************************/
static unsigned int pciGetRegOffset(PCI_HOST host, PCI_REGION region)
{
    switch (host)
    {
	case PCI_HOST0:
	    switch(region) {
		case PCI_IO:		return PCI_0I_O_LOW_DECODE_ADDRESS;
		case PCI_REGION0:	return PCI_0MEMORY0_LOW_DECODE_ADDRESS;
		case PCI_REGION1:	return PCI_0MEMORY1_LOW_DECODE_ADDRESS;
		case PCI_REGION2:	return PCI_0MEMORY2_LOW_DECODE_ADDRESS;
		case PCI_REGION3:	return PCI_0MEMORY3_LOW_DECODE_ADDRESS;
	    }
	case PCI_HOST1:
	    switch(region) {
		case PCI_IO:		return PCI_1I_O_LOW_DECODE_ADDRESS;
		case PCI_REGION0:	return PCI_1MEMORY0_LOW_DECODE_ADDRESS;
		case PCI_REGION1:	return PCI_1MEMORY1_LOW_DECODE_ADDRESS;
		case PCI_REGION2:	return PCI_1MEMORY2_LOW_DECODE_ADDRESS;
		case PCI_REGION3:	return PCI_1MEMORY3_LOW_DECODE_ADDRESS;
	    }
    }
    return PCI_0MEMORY0_LOW_DECODE_ADDRESS;
}

static unsigned int pciGetRemapOffset(PCI_HOST host, PCI_REGION region)
{
    switch (host)
    {
	case PCI_HOST0:
	    switch(region) {
		case PCI_IO:		return PCI_0I_O_ADDRESS_REMAP;
		case PCI_REGION0:	return PCI_0MEMORY0_ADDRESS_REMAP;
		case PCI_REGION1:	return PCI_0MEMORY1_ADDRESS_REMAP;
		case PCI_REGION2:	return PCI_0MEMORY2_ADDRESS_REMAP;
		case PCI_REGION3:	return PCI_0MEMORY3_ADDRESS_REMAP;
	    }
	case PCI_HOST1:
	    switch(region) {
		case PCI_IO:		return PCI_1I_O_ADDRESS_REMAP;
		case PCI_REGION0:	return PCI_1MEMORY0_ADDRESS_REMAP;
		case PCI_REGION1:	return PCI_1MEMORY1_ADDRESS_REMAP;
		case PCI_REGION2:	return PCI_1MEMORY2_ADDRESS_REMAP;
		case PCI_REGION3:	return PCI_1MEMORY3_ADDRESS_REMAP;
	    }
    }
    return PCI_0MEMORY0_ADDRESS_REMAP;
}

bool pciMapSpace(PCI_HOST host, PCI_REGION region, unsigned int remapBase, unsigned int bankBase,unsigned int bankLength)
{
    unsigned int low=0xfff;
    unsigned int high=0x0;
    unsigned int regOffset=pciGetRegOffset(host, region);
    unsigned int remapOffset=pciGetRemapOffset(host, region);

    if(bankLength!=0) {
	low = (bankBase >> 20) & 0xfff;
	high=((bankBase+bankLength)>>20)-1;
    }

    GT_REG_WRITE(regOffset, low | (1<<24));	/* no swapping */
    GT_REG_WRITE(regOffset+8, high);

    if(bankLength!=0) {	/* must do AFTER writing maps */
	GT_REG_WRITE(remapOffset, remapBase>>20);	/* sorry, 32 bits only.
							   dont support upper 32
							   in this driver */
    }
    return true;
}

unsigned int pciGetSpaceBase(PCI_HOST host, PCI_REGION region)
{
    unsigned int low;
    unsigned int regOffset=pciGetRegOffset(host, region);
    GT_REG_READ(regOffset,&low);
    return (low&0xfff)<<20;
}

unsigned int pciGetSpaceSize(PCI_HOST host, PCI_REGION region)
{
    unsigned int low,high;
    unsigned int regOffset=pciGetRegOffset(host, region);
    GT_REG_READ(regOffset,&low);
    GT_REG_READ(regOffset+8,&high);
    high&=0xfff;
    low&=0xfff;
    if(high<=low) return 0;
    return (high+1-low)<<20;
}