Ejemplo n.º 1
0
void ddekit_pci_init_only_one(int skip) 
{	
	/*
	 * If skip is not PCI_TAKE_ALL this function will skip skip PCI DEVICES
	 * and than only take on PCI device.
	 */

	int res, count, more, take_all = 0; 
	
	if (skip == -1) {
		take_all = 1;
	}

	DDEBUG_MSG_INFO("Initializing PCI subsystem...");

	pci_init();

	/*
	 * Iterate the PCI-bus
	 */
	
	more = 1;
	
	for (count = 0 ; count < PCI_MAX_DEVS ; count++) {
		
		struct ddekit_pci_dev *d = &pci_devs[count];
		
		if (more) {
			if ( count==0 ) { 
				res = pci_first_dev(&d->devind, &d->vid, &d->did);
			} else { 
				d->devind = pci_devs[count-1].devind; 
				res = pci_next_dev(&d->devind, &d->vid, &d->did); 
			}
			
			if (res && d->devind!=0 && (take_all || skip == 0)) {  
				
				DDEBUG_MSG_VERBOSE("Found pci device: "
				                   "(ind: %x, vid: %x, did: %x) "
							 	   "mapped to slot %x",
								   d->devind, d->vid, d->did, count);
				d->slot = count;
				d->bus  = 0;
				d->func = 0;
				res = pci_reserve_ok(d->devind);
				if (res != 0) {
					ddekit_panic("ddekit_pci_init_only_one: "
					             "pci_reserve_ok failed (%d)\n",res);
				}
			
			} else {   
				/* no more PCI devices */
				DDEBUG_MSG_VERBOSE("Found %d PCI devices.", count);
				d->devind = -1; 
				more = 0; 
			} /*if (res) */
		} else { 
			d->devind = -1; 
		}
		if (!take_all) {
			skip--;
		}
	} 
}
Ejemplo n.º 2
0
/*===========================================================================*
 *				e1000_probe				     *
 *===========================================================================*/
PRIVATE int e1000_probe(e1000_t *e, int skip)
{
    int i, r, devind;
    u16_t vid, did;
    u32_t status[2];
    u32_t gfpreg, sector_base_addr;
    char *dname;

    E1000_DEBUG(3, ("%s: probe()\n", e->name));

    /*
     * Attempt to iterate the PCI bus. Start at the beginning.
     */
    if ((r = pci_first_dev(&devind, &vid, &did)) == 0)
    {
	return FALSE;
    }
    /* Loop devices on the PCI bus. */
    for(;;)
    {
	for (i = 0; pcitab_e1000[i] != 0; i++)
	{
	    if (vid != 0x8086)
		continue;
	
	    if (did != pcitab_e1000[i])
		continue;
	    else
		break;
	}
	if (pcitab_e1000[i] != 0)
	{
	    if (!skip)
		break;
	    skip--;
	}

	if (!(r = pci_next_dev(&devind, &vid, &did)))
	{
	    return FALSE;
	}
    }
    /*
     * Successfully detected an Intel Pro/1000 on the PCI bus.
     */
    e->status |= E1000_DETECTED;
    e->eeprom_read = eeprom_eerd;
    
    /*
     * Set card specific properties.
     */
    switch (did)
    {
        case E1000_DEV_ID_ICH10_R_BM_LF:
            e->eeprom_read = eeprom_ich;
            break;

    	case E1000_DEV_ID_82574L:
	case E1000_DEV_ID_82541GI_LF:
	    e->eeprom_done_bit = (1 << 1);
	    e->eeprom_addr_off =  2;
	    break;

	default:
	    e->eeprom_done_bit = (1 << 4);
	    e->eeprom_addr_off =  8;
	    break;
    }

    /* Inform the user about the new card. */
    if (!(dname = pci_dev_name(vid, did)))
    {
        dname = "Intel Pro/1000 Gigabit Ethernet Card";
    }
    E1000_DEBUG(1, ("%s: %s (%04x/%04x/%02x) at %s\n",
		     e->name, dname, vid, did, e->revision, 
		     pci_slot_name(devind)));

    /* Reserve PCI resources found. */
    if ((r = pci_reserve_ok(devind)) != OK)
    {
        panic("failed to reserve PCI device: %d", r);
    }
    /* Read PCI configuration. */
    e->irq   = pci_attr_r8(devind, PCI_ILR);
    e->regs  = vm_map_phys(SELF, (void *) pci_attr_r32(devind, PCI_BAR), 
			   0x20000);
			   
    /* Verify mapped registers. */
    if (e->regs == (u8_t *) -1) {
		panic("failed to map hardware registers from PCI");
    }
    /* Optionally map flash memory. */
    if (did != E1000_DEV_ID_82540EM &&
	did != E1000_DEV_ID_82540EP &&
	pci_attr_r32(devind, PCI_BAR_2))
    {
       if((e->flash = vm_map_phys(SELF,
         (void *) pci_attr_r32(devind, PCI_BAR_2), 0x10000)) == MAP_FAILED) {
               if((e->flash = vm_map_phys(SELF,
                       (void *) pci_attr_r32(devind, PCI_BAR_2), 0x1000))
                               == MAP_FAILED) {
                               panic("e1000: couldn't map in flash.");
               }
       }

	gfpreg = E1000_READ_FLASH_REG(e, ICH_FLASH_GFPREG);
        /*
         * sector_base_addr is a "sector"-aligned address (4096 bytes)
         */
        sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;

        /* flash_base_addr is byte-aligned */
        e->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
    }
    /*
     * Output debug information.
     */
    status[0] = e1000_reg_read(e, E1000_REG_STATUS);    
    E1000_DEBUG(3, ("%s: MEM at %p, IRQ %d\n",
		    e->name, e->regs, e->irq));
    E1000_DEBUG(3, ("%s: link %s, %s duplex\n",
		    e->name, status[0] & 3 ? "up"   : "down",
			     status[0] & 1 ? "full" : "half"));
    return TRUE;
}