예제 #1
0
파일: gsc.c 프로젝트: UnitedMarsupials/kame
static	int
gscopen  (dev_t dev, int flags, int fmt, struct proc *p)
{
  struct gsc_unit *scu;
  int unit;

  unit = UNIT(minor(dev)) & UNIT_MASK;
  if ( unit >= NGSC )
    {
#ifdef GSCDEBUG
      /* XXX lprintf isn't valid here since there is no scu. */
      printf("gsc%d.open: unconfigured unit number (max %d)\n", unit, NGSC);
#endif
      return ENXIO;
    }
  scu = unittab + unit;
  if ( !( scu->flags & ATTACHED ) )
    {
      lprintf(("gsc%d.open: unit was not attached successfully 0x%04x\n",
	     unit, scu->flags));
      return ENXIO;
    }

  if ( minor(dev) & DBUG_MASK )
    scu->flags |= FLAG_DEBUG;
  else
    scu->flags &= ~FLAG_DEBUG;

  switch(minor(dev) & FRMT_MASK) {
  case FRMT_PBM:
    scu->flags |= PBM_MODE;
    lprintf(("gsc%d.open: pbm mode\n", unit));
    break;
  case FRMT_RAW:
    lprintf(("gsc%d.open: raw mode\n", unit));
    scu->flags &= ~PBM_MODE;
    break;
  default:
    lprintf(("gsc%d.open: gray maps are not yet supported", unit));
    return ENXIO;
  }

  lprintf(("gsc%d.open: minor %d\n",
	 unit, minor(dev)));

  if ( scu->flags & OPEN )
    {
      lprintf(("gsc%d.open: already open", unit));
      return EBUSY;
    }

  if (isa_dma_acquire(scu->channel))
      return(EBUSY);

  scu->flags |= OPEN;

  return SUCCESS;
}
예제 #2
0
int
ppc_isa_attach(device_t dev)
{
	struct ppc_data *ppc = device_get_softc(dev);

	if ((ppc->ppc_avm & PPB_ECP) && (ppc->ppc_dmachan > 0)) {
		/* acquire the DMA channel forever */   /* XXX */
		isa_dma_acquire(ppc->ppc_dmachan);
		isa_dmainit(ppc->ppc_dmachan, 1024); /* nlpt.BUFSIZE */
		ppc->ppc_dmadone = ppc_isa_dmadone;
	}

	return (ppc_attach(dev));
}
예제 #3
0
파일: ppc.c 프로젝트: MarginC/kame
int
ppc_attach(device_t dev)
{
	struct ppc_data *ppc = DEVTOSOFTC(dev);

	device_t ppbus;
	device_t parent = device_get_parent(dev);

	device_printf(dev, "%s chipset (%s) in %s mode%s\n",
		      ppc_models[ppc->ppc_model], ppc_avms[ppc->ppc_avm],
		      ppc_modes[ppc->ppc_mode], (PPB_IS_EPP(ppc->ppc_mode)) ?
		      ppc_epp_protocol[ppc->ppc_epp] : "");
	
	if (ppc->ppc_fifo)
		device_printf(dev, "FIFO with %d/%d/%d bytes threshold\n",
			      ppc->ppc_fifo, ppc->ppc_wthr, ppc->ppc_rthr);

	if ((ppc->ppc_avm & PPB_ECP) && (ppc->ppc_dmachan > 0)) {
		/* acquire the DMA channel forever */	/* XXX */
		isa_dma_acquire(ppc->ppc_dmachan);
		isa_dmainit(ppc->ppc_dmachan, 1024); /* nlpt.BUFSIZE */
	}

	/* add ppbus as a child of this isa to parallel bridge */
	ppbus = device_add_child(dev, "ppbus", -1);

	/*
	 * Probe the ppbus and attach devices found.
	 */
	device_probe_and_attach(ppbus);

	/* register the ppc interrupt handler as default */
	if (ppc->res_irq) {
		/* default to the tty mask for registration */	/* XXX */
		if (BUS_SETUP_INTR(parent, dev, ppc->res_irq, INTR_TYPE_TTY,
					    ppcintr, dev, &ppc->intr_cookie) == 0) {

			/* remember the ppcintr is registered */
			ppc->ppc_registered = 1;
		}
	}

	return (0);
}
예제 #4
0
static int
dpt_isa_attach (device_t dev)
{
	dpt_softc_t *	dpt;
	int		error = 0;

	dpt = device_get_softc(dev);
	dpt->dev = dev;
	dpt_alloc(dev);

	dpt->io_rid = 0;
	dpt->io_type = SYS_RES_IOPORT;
	dpt->irq_rid = 0;

	error = dpt_alloc_resources(dev);
	if (error) {
		goto bad;
	}

	dpt->drq_rid = 0;
	dpt->drq_res = bus_alloc_resource_any(dev, SYS_RES_DRQ, &dpt->drq_rid,
					RF_ACTIVE);
	if (!dpt->drq_res) {
		device_printf(dev, "No DRQ!\n");
		error = ENOMEM;
		goto bad;
	}
	isa_dma_acquire(rman_get_start(dpt->drq_res));
	isa_dmacascade(rman_get_start(dpt->drq_res));

	/* Allocate a dmatag representing the capabilities of this attachment */
	if (bus_dma_tag_create( /* parent    */	bus_get_dma_tag(dev),
				/* alignemnt */	1,
				/* boundary  */	0,
				/* lowaddr   */	BUS_SPACE_MAXADDR_32BIT,
				/* highaddr  */	BUS_SPACE_MAXADDR,
				/* filter    */	NULL,
				/* filterarg */	NULL,
				/* maxsize   */	BUS_SPACE_MAXSIZE_32BIT,
				/* nsegments */	~0,
				/* maxsegsz  */	BUS_SPACE_MAXSIZE_32BIT,
				/* flags     */	0,
				/* lockfunc  */ NULL,
				/* lockarg   */ NULL,
				&dpt->parent_dmat) != 0) {
		error = ENXIO;
		goto bad;
	}

	if (dpt_init(dpt) != 0) {
		error = ENXIO;
		goto bad;
	}

	/* Register with the XPT */
	dpt_attach(dpt);

	if (bus_setup_intr(dev, dpt->irq_res, INTR_TYPE_CAM | INTR_ENTROPY |
	    INTR_MPSAFE, NULL, dpt_intr, dpt, &dpt->ih)) {
		device_printf(dev, "Unable to register interrupt handler\n");
		error = ENXIO;
		goto bad;
	}

	return (error);

 bad:
	if (dpt->drq_res) {
		isa_dma_release(rman_get_start(dpt->drq_res));
	}

	dpt_release_resources(dev);

	if (dpt)
		dpt_free(dpt);

	return (error);
}