Exemplo n.º 1
0
Arquivo: atl2.c Projeto: ssinghi/minix
/*===========================================================================*
 *				atl2_probe				     *
 *===========================================================================*/
static int atl2_probe(int skip)
{
	/* Find a matching PCI device.
	 */
	u16_t vid, did;
	char *dname;
	int r, devind;

	pci_init();

	r = pci_first_dev(&devind, &vid, &did);
	if (r <= 0)
		return -1;

	while (skip--) {
		r = pci_next_dev(&devind, &vid, &did);
		if (r <= 0)
			return -1;
	}

	dname = pci_dev_name(vid, did);
	ATL2_DEBUG(("ATL2: found %s (%x/%x) at %s\n",
		dname ? dname : "<unknown>", vid, did,
		pci_slot_name(devind)));

	pci_reserve(devind);

	return devind;
}
Exemplo n.º 2
0
/*===========================================================================*
 *				root_pci				     *
 *===========================================================================*/
static void root_pci(void)
{
	/* Print information about PCI devices present in the system.
	 */
	u16_t vid, did;
	u8_t bcr, scr, pifr;
	char *slot_name, *dev_name;
	int r, devind;
	static int first = TRUE;

	/* This should be taken care of behind the scenes by the PCI lib. */
	if (first) {
		pci_init();
		first = FALSE;
	}

	/* Iterate over all devices, printing info for each of them. */
	r = pci_first_dev(&devind, &vid, &did);
	while (r == 1) {
		slot_name = pci_slot_name(devind);
		dev_name = pci_dev_name(vid, did);

		bcr = pci_attr_r8(devind, PCI_BCR);
		scr = pci_attr_r8(devind, PCI_SCR);
		pifr = pci_attr_r8(devind, PCI_PIFR);

		buf_printf("%s %x/%x/%x %04X:%04X %s\n",
			slot_name ? slot_name : "-",
			bcr, scr, pifr, vid, did,
			dev_name ? dev_name : "");

		r = pci_next_dev(&devind, &vid, &did);
	}
}
Exemplo n.º 3
0
static int de_probe(dpeth_t *dep, int skip)
{
  int i, r, devind;
  u16_t vid, did, temp16;

  DEBUG(printf("PROBING..."));
  
  r= pci_first_dev(&devind, &vid, &did);
  if (r == 0)
    return FALSE;

  while (skip--)
    {
      r= pci_next_dev(&devind, &vid, &did);
      if (!r)
	return FALSE;
    }

  pci_reserve(devind);

  dep->de_base_port = pci_attr_r32(devind, PCI_BAR) & 0xffffffe0;
  dep->de_irq = pci_attr_r8(devind, PCI_ILR);

  if (dep->de_base_port < DE_MIN_BASE_ADDR)
    panic("de_probe: base address invalid: %d", dep->de_base_port);

  DEBUG(printf("%s: using I/O address 0x%lx, IRQ %d\n",
	       dep->de_name, (unsigned long)dep->de_base_port, 
	       dep->de_irq));

  dep->de_type = pci_attr_r8(devind, PCI_REV);

  /* device validation. We support only the DEC21140A */
  if(dep->de_type != DEC_21140A){
    dep->de_type = DE_TYPE_UNKNOWN;
    printf("%s: unsupported device\n", str_DevName);
    return FALSE;
  }

  de_reset(dep);

  DEBUG(printf("Reading SROM...\n"));

  for(i=0;i<(1<<SROM_BITWIDTH)-1;i++){
    temp16 = de_read_rom(dep, i, SROM_BITWIDTH);
    dep->srom[i*2] = temp16 & 0xFF;
    dep->srom[i*2+1] = temp16 >> 8;
  }

  /* TODO: validate SROM content */
  /* acquire MAC addr */
  DEBUG(printf("Using MAC addr= "));
  for(i=0;i<6;i++){
    dep->de_address.ea_addr[i] = dep->srom[i+DE_SROM_EA_OFFSET];
    DEBUG(printf("%02X%c",dep->de_address.ea_addr[i],i!=5?'-':'\n'));
  }
  DEBUG(printf("probe success\n"));
  return TRUE;
}
Exemplo n.º 4
0
/*===========================================================================*
 *				vbox_init				     *
 *===========================================================================*/
static int vbox_init(int UNUSED(type), sef_init_info_t *UNUSED(info))
{
	/* Initialize the device. */
	int devind;
	u16_t vid, did;
	struct VMMDevReportGuestInfo *req;
	int r;

	interval = DEFAULT_INTERVAL;
	drift = DEFAULT_DRIFT;

	if (env_argc > 1)
		optset_parse(optset_table, env_argv[1]);

	pci_init();

	r = pci_first_dev(&devind, &vid, &did);

	for (;;) {
		if (r != 1)
			panic("backdoor device not found");

		if (vid == VMMDEV_PCI_VID && did == VMMDEV_PCI_DID)
			break;

		r = pci_next_dev(&devind, &vid, &did);
	}

	pci_reserve(devind);

	port = pci_attr_r32(devind, PCI_BAR) & PCI_BAR_IO_MASK;

	irq = pci_attr_r8(devind, PCI_ILR);
	hook_id = 0;

	if ((r = sys_irqsetpolicy(irq, 0 /* IRQ_REENABLE */, &hook_id)) != OK)
		panic("unable to register IRQ: %d", r);

	if ((r = sys_irqenable(&hook_id)) != OK)
		panic("unable to enable IRQ: %d", r);

	if ((vir_ptr = alloc_contig(VMMDEV_BUF_SIZE, 0, &phys_ptr)) == NULL)
		panic("unable to allocate memory");

	req = (struct VMMDevReportGuestInfo *) vir_ptr;
	req->add_version = VMMDEV_GUEST_VERSION;
	req->os_type = VMMDEV_GUEST_OS_OTHER;

	if ((r = vbox_request(&req->header, phys_ptr,
			VMMDEV_REQ_REPORTGUESTINFO, sizeof(*req))) !=
			VMMDEV_ERR_OK)
		panic("backdoor device not functioning");

	ticks = sys_hz() * interval;

	sys_setalarm(ticks, 0);

	return OK;
}
Exemplo n.º 5
0
static int detect_hw(void) {
	u32_t device;
	int devind;
	u16_t v_id, d_id;

	/* detect_hw tries to find device and get IRQ and base address
	   with a little (much) help from the PCI library. 
	   This code is quite device independent and you can copy it. 
	   (just make sure to get the bugs out first)*/

	pci_init();
	/* get first device and then search through the list */
	device = pci_first_dev(&devind, &v_id, &d_id);
	while( device > 0 ) {
		/* if we have a match...break */
		if (v_id == VENDOR_ID && d_id == DEVICE_ID) break;
		device = pci_next_dev(&devind, &v_id, &d_id);
	}

	/* did we find anything? */
	if (v_id != VENDOR_ID || d_id != DEVICE_ID) {
		return EIO;
	}

	pci_reserve(devind);

	dev.name = pci_dev_name(v_id, d_id);

	/* get base address of our device, ignore least signif. bit 
	   this last bit thing could be device dependent, i don't know */
	dev.base = pci_attr_r32(devind, PCI_BAR) & 0xfffffffe;

	/* get IRQ */
	dev.irq = pci_attr_r8(devind, PCI_ILR);  
	dev.revision = pci_attr_r8(devind, PCI_REV);
	dev.d_id = d_id;
	dev.v_id = v_id;
	dev.devind = devind; /* pci device identifier */

	return OK;
}
Exemplo n.º 6
0
/*===========================================================================*
 *				hw_probe				     *
 *===========================================================================*/
static int hw_probe(int skip)
{
    u16_t vid, did;
    int devind;

    pci_init();

    if (pci_first_dev(&devind, &vid, &did) != 1)
        return(-1);

    while (skip--)
        if (pci_next_dev(&devind, &vid, &did) != 1)
            return(-1);

    pci_reserve(devind);

    if (debug)
        printf("ti1225: found device %04x/%04x\n", vid, did);

    return(devind);
}
Exemplo n.º 7
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--;
		}
	} 
}
Exemplo n.º 8
0
struct virtio_device *
virtio_setup_device(u16_t subdevid, const char *name,
		struct virtio_feature *features, int num_features,
		int threads, int skip)
{
	int r, devind;
	u16_t vid, did, sdid;
	struct virtio_device *ret;

	/* bogus values? */
	if (skip < 0 || name == NULL || num_features < 0 || threads <= 0)
		return NULL;

	pci_init();

	r = pci_first_dev(&devind, &vid, &did);

	while (r > 0) {
		sdid = pci_attr_r16(devind, PCI_SUBDID);
		if (is_matching_device(subdevid, vid, sdid)) {

			/* this is the device we are looking for */
			if (skip == 0)
				break;

			skip--;
		}

		r = pci_next_dev(&devind, &vid, &did);
	}

	/* pci_[first|next_dev()] return 0 if no device was found */
	if (r == 0 || skip > 0)
		return NULL;

	/* allocate and set known info about the device */
	ret = malloc(sizeof(*ret));

	if (ret == NULL)
		return NULL;

	/* Prepare virtio_device intance */
	memset(ret, 0, sizeof(*ret));
	ret->name = name;
	ret->features = features;
	ret->num_features = num_features;
	ret->threads = threads;
	/* see comment in the beginning of this file */
	ret->num_indirect = threads;

	if (init_device(devind, ret) != OK) {
		printf("%s: Could not initialize device\n", ret->name);
		goto err;
	}

	/* Ack the device */
	virtio_write8(ret, VIRTIO_DEV_STATUS_OFF, VIRTIO_STATUS_ACK);

	if (exchange_features(ret) != OK) {
		printf("%s: Could not exchange features\n", ret->name);
		goto err;
	}

	if (init_indirect_desc_tables(ret) != OK) {
		printf("%s: Could not initialize indirect tables\n", ret->name);
		goto err;
	}

	/* We know how to drive the device... */
	virtio_write8(ret, VIRTIO_DEV_STATUS_OFF, VIRTIO_STATUS_DRV);

	return ret;

/* Error path */
err:
	free(ret);
	return NULL;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
/*
 * Find a matching device.  Return TRUE on success.
 */
static int
e1000_probe(e1000_t * e, int skip)
{
	int r, devind, ioflag;
	u16_t vid, did, cr;
	u32_t status;
	u32_t base, size;
	char *dname;

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

	/* Initialize communication to the PCI driver. */
	pci_init();

	/* 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. */
	while (skip--) {
		E1000_DEBUG(3, ("%s: probe() devind %d vid 0x%x did 0x%x\n",
		    e->name, devind, vid, did));

		if (!(r = pci_next_dev(&devind, &vid, &did)))
			return FALSE;
	}

	/* We found a matching card.  Set card-specific properties. */
	e->eeprom_read = eeprom_eerd;

	switch (did) {
	case E1000_DEV_ID_ICH10_D_BM_LM:
	case E1000_DEV_ID_ICH10_R_BM_LF:
		e->eeprom_read = eeprom_ich;
		break;

	case E1000_DEV_ID_82540EM:
	case E1000_DEV_ID_82545EM:
	case E1000_DEV_ID_82540EP_LP:
		e->eeprom_done_bit = (1 << 4);
		e->eeprom_addr_off = 8;
		break;

	default:
		e->eeprom_done_bit = (1 << 1);
		e->eeprom_addr_off = 2;
		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) at %s\n",
	    e->name, dname, vid, did, pci_slot_name(devind)));

	/* Reserve PCI resources found. */
	pci_reserve(devind);

	/* Read PCI configuration. */
	e->irq = pci_attr_r8(devind, PCI_ILR);

	if ((r = pci_get_bar(devind, PCI_BAR, &base, &size, &ioflag)) != OK)
		panic("failed to get PCI BAR: %d", r);
	if (ioflag)
		panic("PCI BAR is not for memory");

	if ((e->regs = vm_map_phys(SELF, (void *)base, size)) == MAP_FAILED)
		panic("failed to map hardware registers from PCI");

	/* Enable DMA bus mastering if necessary. */
	cr = pci_attr_r16(devind, PCI_CR);
	if (!(cr & PCI_CR_MAST_EN))
		pci_attr_w16(devind, PCI_CR, cr | PCI_CR_MAST_EN);

	/* Optionally map flash memory. */
	e1000_map_flash(e, devind, did);

	/* Output debug information. */
	status = 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 & 3 ? "up"   : "down", status & 1 ? "full" : "half"));

	return TRUE;
}