| 711 | static int zy7_devcfg_detach(device_t dev); |
| 712 | |
| 713 | static int |
| 714 | zy7_devcfg_attach(device_t dev) |
| 715 | { |
| 716 | struct zy7_devcfg_softc *sc = device_get_softc(dev); |
| 717 | int i; |
| 718 | int rid, err; |
| 719 | |
| 720 | /* Allow only one attach. */ |
| 721 | if (zy7_devcfg_softc_p != NULL) |
| 722 | return (ENXIO); |
| 723 | |
| 724 | sc->dev = dev; |
| 725 | |
| 726 | DEVCFG_SC_LOCK_INIT(sc); |
| 727 | |
| 728 | /* Get memory resource. */ |
| 729 | rid = 0; |
| 730 | sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, |
| 731 | RF_ACTIVE); |
| 732 | if (sc->mem_res == NULL) { |
| 733 | device_printf(dev, "could not allocate memory resources.\n"); |
| 734 | zy7_devcfg_detach(dev); |
| 735 | return (ENOMEM); |
| 736 | } |
| 737 | |
| 738 | /* Allocate IRQ. */ |
| 739 | rid = 0; |
| 740 | sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, |
| 741 | RF_ACTIVE); |
| 742 | if (sc->irq_res == NULL) { |
| 743 | device_printf(dev, "cannot allocate IRQ\n"); |
| 744 | zy7_devcfg_detach(dev); |
| 745 | return (ENOMEM); |
| 746 | } |
| 747 | |
| 748 | /* Activate the interrupt. */ |
| 749 | err = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC | INTR_MPSAFE, |
| 750 | NULL, zy7_devcfg_intr, sc, &sc->intrhandle); |
| 751 | if (err) { |
| 752 | device_printf(dev, "cannot setup IRQ\n"); |
| 753 | zy7_devcfg_detach(dev); |
| 754 | return (err); |
| 755 | } |
| 756 | |
| 757 | /* Create /dev/devcfg */ |
| 758 | sc->sc_ctl_dev = make_dev(&zy7_devcfg_cdevsw, 0, |
| 759 | UID_ROOT, GID_WHEEL, 0600, "devcfg"); |
| 760 | if (sc->sc_ctl_dev == NULL) { |
| 761 | device_printf(dev, "failed to create /dev/devcfg"); |
| 762 | zy7_devcfg_detach(dev); |
| 763 | return (ENXIO); |
| 764 | } |
| 765 | sc->sc_ctl_dev->si_drv1 = sc; |
| 766 | |
| 767 | zy7_devcfg_softc_p = sc; |
| 768 | |
| 769 | /* Unlock devcfg registers. */ |
| 770 | WR4(sc, ZY7_DEVCFG_UNLOCK, ZY7_DEVCFG_UNLOCK_MAGIC); |
nothing calls this directly
no test coverage detected