Ejemplo n.º 1
0
//subscribe mouse interrupts
int mouse_subscribe_int(void)
{
	int returnvalue = BIT(mouse_hook_id);
	int irqpolicy = IRQ_EXCLUSIVE | IRQ_REENABLE;
	if(sys_irqsetpolicy(MOUSE_IRQ, irqpolicy, &mouse_hook_id)!= OK){
		printf("mouse_subscribe_int(): sys_irqsetpolicy() failed\n");
		return -1;
	}

	if(sys_irqenable(&mouse_hook_id)!=OK){
		printf("mouse_subscribe_int(): sys_irqenable() failed\n");
		return -1;
	}
	return returnvalue;//return value with bit number (original hook_id) set to 1
}
Ejemplo n.º 2
0
int timer_subscribe_int(void) {
	// atualiza hook_id, passando a ser 0
	hook_id = TIMER_HOOK_BIT;

	int bitmask = BIT(hook_id);
	/*The policy you should specify in sys_irqsetpolicy() is IRQ_REENABLE, so
	 that the generic interrupt handler will acknowledge the interrupt. */
	if (sys_irqsetpolicy(TIMER0_IRQ, IRQ_REENABLE, &hook_id) != 0
			|| sys_irqenable(&hook_id) != 0) {
		printf("\ntimer_subscribe_int() failed \n");
		return -1;
	} else {
		return bitmask;
	}
}
Ejemplo n.º 3
0
Archivo: kbd.c Proyecto: pedro93/LCOM
int keyboard_subscribe_int()
{
if(sys_irqsetpolicy(IRQ_KBD,(IRQ_REENABLE|IRQ_EXCLUSIVE),&hook_id_kbd)!=OK)
{
	printf("IRQ_SETPOLICY failure /n");
	return -1;
}
if(sys_irqenable(&hook_id_kbd)!=OK)
{
	printf("IRQENABLE failure /n");
	return -1;
}

return hook_id_kbd;
}
Ejemplo n.º 4
0
int kbd_subscribe_int(void ){

	//para nao perder o valor original de khook_id (vai ser preciso para depois reconhecer a notificacao)
		int hook_temp = khook_id;

		if (OK == sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, &khook_id))
		{
			if (OK == sys_irqenable(&khook_id))
			{
				return BIT(hook_temp);
			}
		}
		return -1;

}
Ejemplo n.º 5
0
PRIVATE void handle_hw_intr(void)
{
	dpeth_t *dep;

	dep = &de_state;

	/* If device is enabled and interrupt pending */
	if (dep->de_mode == DEM_ENABLED) {
		dep->de_int_pending = TRUE;
		(*dep->de_interruptf) (dep);
		if (dep->de_flags & (DEF_ACK_SEND | DEF_ACK_RECV))
			reply(dep);
		dep->de_int_pending = FALSE;
		sys_irqenable(&dep->de_hook);
	}
}
Ejemplo n.º 6
0
int MOUSE_subscribe_int(void) {

	int hook;

	hook = hook_id2;

	if (sys_irqsetpolicy(MOUSE_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE,

			&hook_id2) == OK)

		if (sys_irqenable(&hook_id2) == OK)

			return BIT(hook);

	return -1;

}
Ejemplo n.º 7
0
int subscribeKeyboard()
{
	// IRQ_EXCLUSIVE is needed to prevent minix from printing the character in the terminal
	if (sys_irqsetpolicy(KB_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, &kb_id) != OK)
	{
		printf("\tsubscribeKeyboard() in Keyboard.c: sys_irqsetpolicy failed");
		return -1;
	}

	if (sys_irqenable(&kb_id) != OK)
	{
		printf("\tsubscribeKeyboard() in Keyboard.c: sys_irqenable failed");
		return -1;
	}

	return BIT(0);
}
Ejemplo n.º 8
0
PRIVATE int get_started(sub_dev_t *sub_dev_ptr) {
  u32_t i;char c;  
  
  /* enable interrupt messages from MINIX */
  if ((i=sys_irqenable(&irq_hook_id)) != OK) {
    error("%s: Couldn't enable IRQs",drv.DriverName);
    return EIO;
  }
  /* let the lower part of the driver start the device */
  if (drv_start(sub_dev_ptr->Nr, sub_dev_ptr->DmaMode) != OK) {
    error("%s: Could not start device %d\n", drv.DriverName, sub_dev_ptr->Nr);
  }
  
  sub_dev_ptr->DmaBusy = TRUE;     /* Dma is busy from now on */
	sub_dev_ptr->DmaReadNext = 0;    
  return OK;
}
Ejemplo n.º 9
0
static int
intr_enable(void)
{
	int r;
	uint8_t val;
	static int policy_set = 0;
	static int irq_enabled = 0;

	/* Enable IRQ */
	if (!policy_set) {
		r = sys_irqsetpolicy(irq, 0, &irq_hook_kernel_id);
		if (r == OK) {
			policy_set = 1;
		} else {
			log_warn(&log, "Couldn't set irq policy\n");
			return -1;
		}
	}
	if (policy_set && !irq_enabled) {
		r = sys_irqenable(&irq_hook_kernel_id);
		if (r == OK) {
			irq_enabled = 1;
		} else {
			log_warn(&log, "Couldn't enable irq %d (hooked)\n",
			    irq);
			return -1;
		}
	}

	/* Enable/Disable interrupts in the TPS65217 */
	r = reg_write(INT_REG, DEFAULT_INT_MASK);
	if (r != OK) {
		log_warn(&log, "Failed to set interrupt mask.\n");
		return -1;
	}

	/* Read from the interrupt register to clear any pending interrupts */
	r = reg_read(INT_REG, &val);
	if (r != OK) {
		log_warn(&log, "Failed to read interrupt register.\n");
		return -1;
	}

	return OK;
}
Ejemplo n.º 10
0
/*===========================================================================*
 *				do_initialize				     *
 *===========================================================================*/
static void do_initialize()
{
/* Set global variables and initialize the printer. */
  if(sys_outb(port_base + 2, INIT_PRINTER) != OK) {
	printf("printer: sys_outb of %x failed\n", port_base+2);
	panic("do_initialize: sys_outb init failed");
  }
  micro_delay(1000000/20);	/* easily satisfies Centronics minimum */
  if(sys_outb(port_base + 2, PR_SELECT) != OK) {
	printf("printer: sys_outb of %x failed\n", port_base+2);
	panic("do_initialize: sys_outb select failed");
  }
  irq_hook_id = 0;
  if(sys_irqsetpolicy(PRINTER_IRQ, 0, &irq_hook_id) != OK ||
     sys_irqenable(&irq_hook_id) != OK) {
	panic("do_initialize: irq enabling failed");
  }
}
Ejemplo n.º 11
0
int sp2_subscribe_int()
{
	int hook_temp = hook_id_sp2;

	if (sys_irqsetpolicy(COM2_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, &hook_id_sp2) != OK)
	{
		printf("SET POlicy\n");
		return -1;
	}

	if (sys_irqenable(&hook_id_sp2) != OK)
	{
		printf("irq enable\n");
		return -1;
	}

	return BIT(hook_temp);
}
Ejemplo n.º 12
0
/*===========================================================================*
 *				dsp_init
 *===========================================================================*/
PRIVATE int dsp_init()
{
	int i, s;

	if(dsp_reset () != OK) { 
		dprint("sb16: No SoundBlaster card detected\n");
		return -1;
	}

	DspVersion[0] = DspVersion[1] = 0;
	dsp_command(DSP_GET_VERSION);	/* Get DSP version bytes */

	for(i = 1000; i; i--) {
		if(sb16_inb(DSP_DATA_AVL) & 0x80) {		
			if(DspVersion[0] == 0) {
				DspVersion[0] = sb16_inb(DSP_READ);
			} else {
				DspVersion[1] = sb16_inb(DSP_READ);
				break;
			}
		}
	}

	if(DspVersion[0] < 4) {
		dprint("sb16: No SoundBlaster 16 compatible card detected\n");
		return -1;
	} 
	
	dprint("sb16: SoundBlaster DSP version %d.%d detected\n", DspVersion[0], DspVersion[1]);

	/* set SB to use our IRQ and DMA channels */
	mixer_set(MIXER_SET_IRQ, (1 << (SB_IRQ / 2 - 1)));
	mixer_set(MIXER_SET_DMA, (1 << SB_DMA_8 | 1 << SB_DMA_16)); 

	/* register interrupt vector and enable irq */
	if ((s=sys_irqsetpolicy(SB_IRQ, IRQ_REENABLE, &irq_hook_id )) != OK)
  		panic("Couldn't set IRQ policy: %d", s);
	if ((s=sys_irqenable(&irq_hook_id)) != OK)
  		panic("Couldn't enable IRQ: %d", s);

	DspAvail = 1;
	return OK;
}
Ejemplo n.º 13
0
Archivo: atl2.c Proyecto: ssinghi/minix
/*===========================================================================*
 *				atl2_init				     *
 *===========================================================================*/
static void atl2_init(int devind)
{
	/* Initialize the device.
	 */
	u32_t bar;
	int r, flag;

	/* Initialize global state. */
	state.devind = devind;
	state.mode = DL_NOMODE;
	state.flags = 0;
	state.recv_count = 0;

	memset(&state.stat, 0, sizeof(state.stat));

	if ((r = pci_get_bar(devind, PCI_BAR, &bar, &state.size, &flag)) != OK)
		panic("unable to retrieve bar: %d", r);

	if (state.size < ATL2_MIN_MMAP_SIZE || flag)
		panic("invalid register bar");

	state.base = vm_map_phys(SELF, (void *) bar, state.size);
	if (state.base == MAP_FAILED)
		panic("unable to map in registers");

	if ((r = atl2_alloc_dma()) != OK)
		panic("unable to allocate DMA buffers: %d", r);

	state.irq = pci_attr_r8(devind, PCI_ILR);

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

	if (!atl2_reset())
		panic("unable to reset hardware");

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

	atl2_get_hwaddr();

	atl2_setup();
}
Ejemplo n.º 14
0
/* handle interrupt for specified sub device; DmaMode == DEV_READ */
PRIVATE void handle_int_read(int sub_dev_nr) 
{
  sub_dev_t *sub_dev_ptr; int r,i;
  
  sub_dev_ptr = &sub_dev[sub_dev_nr];
  
  dprint("Device filled dma[%d]\n", sub_dev_ptr->DmaFillNext);
  sub_dev_ptr->DmaLength += 1; 
  sub_dev_ptr->DmaFillNext = (sub_dev_ptr->DmaFillNext + 1) % sub_dev_ptr->NrOfDmaFragments;

  /* possibly copy data to user (if it is waiting for us) */
  data_to_user(sub_dev_ptr);
  
	if (sub_dev_ptr->DmaLength == sub_dev_ptr->NrOfDmaFragments) { /* if dma buffer full */
    
    if (sub_dev_ptr->BufLength == sub_dev_ptr->NrOfExtraBuffers) {
      error("All buffers full, we have a problem.\n");
      drv_stop(sub_dev_nr);        /* stop the sub device */
      sub_dev_ptr->DmaBusy = FALSE;
      sub_dev_ptr->ReviveStatus = 0;   /* no data for user, this is a sad story */
      sub_dev_ptr->ReadyToRevive = TRUE; /* wake user up */
      return;
    } 
    else { /* dma full, still room in extra buf; copy from dma to extra buf */
      dprint("dma full: going to copy buf[%d] <- dma[%d]\n", sub_dev_ptr->BufFillNext, 
                                                       sub_dev_ptr->DmaReadNext);
      memcpy(sub_dev_ptr->ExtraBuf + sub_dev_ptr->BufFillNext * sub_dev_ptr->FragSize, 
                sub_dev_ptr->DmaPtr + sub_dev_ptr->DmaReadNext * sub_dev_ptr->FragSize,
                                                         sub_dev_ptr->FragSize);
      sub_dev_ptr->DmaLength -= 1;
      sub_dev_ptr->DmaReadNext = (sub_dev_ptr->DmaReadNext + 1) % sub_dev_ptr->NrOfDmaFragments;
      sub_dev_ptr->BufFillNext = (sub_dev_ptr->BufFillNext + 1) % sub_dev_ptr->NrOfExtraBuffers;
    }
  }
  /* confirm interrupt, and reenable interrupt from this sub dev*/
  drv_reenable_int(sub_dev_ptr->Nr);
  
  /* reenable irq_hook*/
  if ((r=sys_irqenable(&irq_hook_id)) != OK) {
    error("%s: Couldn't reenable IRQ", drv.DriverName);
 	}
}
Ejemplo n.º 15
0
Archivo: dp.c Proyecto: ssinghi/minix
/*
**  Name:	void do_first_init(dpeth_t *dep, dp_conf_t *dcp);
**  Function:	Init action to setup task
*/
static void do_first_init(dpeth_t *dep, const dp_conf_t *dcp)
{

  dep->de_linmem = 0xFFFF0000;

  /* Make sure statisics are cleared */
  memset((void *) &(dep->de_stat), 0, sizeof(eth_stat_t));

  /* Device specific initialization */
  (*dep->de_initf) (dep);

  /* Set the interrupt handler policy. Request interrupts not to be reenabled
   * automatically. Return the IRQ line number when an interrupt occurs.
   */
  dep->de_hook = dep->de_irq;
  sys_irqsetpolicy(dep->de_irq, 0 /*IRQ_REENABLE*/, &dep->de_hook);
  dep->de_int_pending = FALSE;
  sys_irqenable(&dep->de_hook);

  return;
}
Ejemplo n.º 16
0
int subscribe_int(int irq_vec, int policy, int *hook_id)
{
	int status, tmp = *hook_id;

	// IRQ_EXCLUSIVE is needed to prevent minix from printing the character in the terminal
	status = sys_irqsetpolicy(irq_vec, policy, hook_id);
	if (status != OK)
	{
		printf("sys_irqsetpolicy failed with: %d", status);
		return -1;
	}

	status = sys_irqenable(hook_id);
	if (status != OK)
	{
		printf("sys_irqenable failed with: %d", status);
		return -1;
	}

	return BIT(tmp);
}
Ejemplo n.º 17
0
int keyboard_subscribe_int()
{
	int status, tmp = kb_id;

	// IRQ_EXCLUSIVE is needed to prevent minix from printing the character in the terminal
	status = sys_irqsetpolicy(KB_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, &kb_id);
	if (status != OK)
	{
		printf("sys_irqsetpolicy failed with: %d", status);
		return -1;
	}

	status = sys_irqenable(&kb_id);
	if (status != OK)
	{
		printf("sys_irqenable failed with: %d", status);
		return -1;
	}

	return BIT(tmp);
}
Ejemplo n.º 18
0
static void handle_hw_intr(void)
{
	int r, irq;
	dpeth_t *dep;

	dep = &de_state;

	if (dep->de_mode != DEM_ENABLED)
		return;
	assert(dep->de_flags & DEF_ENABLED);
	irq= dep->de_irq;
	assert(irq >= 0 && irq < NR_IRQ_VECTORS);
	if (dep->de_int_pending || 1)
	{
		dep->de_int_pending= 0;
		dp_check_ints(dep);
		do_int(dep);
		r= sys_irqenable(&dep->de_hook);
		if (r != OK) {
			panic("unable enable interrupts: %d", r);
		}
	}
}
Ejemplo n.º 19
0
/*===========================================================================*
 *				w_intr_wait				     *
 *===========================================================================*/
static int
intr_wait(int mask)
{
	long v;
#ifdef USE_INTR
	if (sys_irqenable(&hook_id) != OK)
		printf("Failed to enable irqenable irq\n");
	/* Wait for a task completion interrupt. */
	message m;
	int ipc_status;
	int ticks = SANE_TIMEOUT * sys_hz() / 1000000;

	if (ticks <= 0)
		ticks = 1;
	while (1) {
		int rr;
		sys_setalarm(ticks, 0);
		if ((rr = driver_receive(ANY, &m, &ipc_status)) != OK) {
			panic("driver_receive failed: %d", rr);
		};
		if (is_ipc_notify(ipc_status)) {
			switch (_ENDPOINT_P(m.m_source)) {
			case CLOCK:
				/* Timeout. */
				// w_timeout(); /* a.o. set w_status */
				mmc_log_warn(&log, "TIMEOUT\n");
				return 1;
				break;
			case HARDWARE:
				v = read32(base_address + MMCHS_SD_STAT);
				if (v & mask) {
					sys_setalarm(0, 0);
					return 0;
				} else if (v & (1 << 15)) {
					return 1;	/* error */
				} else {
					mmc_log_debug(&log,
					    "unexpected HW interrupt 0x%08x mask 0X%08x\n",
					    v, mask);
					if (sys_irqenable(&hook_id) != OK)
						printf
						    ("Failed to re-enable irqenable irq\n");
					continue;
					// return 1;
				}
			default:
				/* 
				 * unhandled message.  queue it and
				 * handle it in the blockdriver loop.
				 */
				blockdriver_mq_queue(&m, ipc_status);
			}
		} else {
			mmc_log_debug(&log, "Other\n");
			/* 
			 * unhandled message.  queue it and handle it in the
			 * blockdriver loop.
			 */
			blockdriver_mq_queue(&m, ipc_status);
		}
	}
	sys_setalarm(0, 0);	/* cancel the alarm */

#else
	spin_t spin;
	spin_init(&spin, SANE_TIMEOUT);
	/* Wait for completion */
	int counter = 0;
	while (1 == 1) {
		counter++;
		v = read32(base_address + MMCHS_SD_STAT);
		if (spin_check(&spin) == FALSE) {
			mmc_log_warn(&log,
			    "Timeout waiting for interrupt (%d) value 0x%08x mask 0x%08x\n",
			    counter, v, mask);
			return 1;
		}
		if (v & mask) {
			return 0;
		} else if (v & 0xFF00) {
			mmc_log_debug(&log,
			    "unexpected HW interrupt (%d) 0x%08x mask 0x%08x\n",
			    v, mask);
			return 1;
		}
	}
	return 1;		/* unreached */
#endif /* USE_INTR */
}
Ejemplo n.º 20
0
/*===========================================================================*
 *				hw_init					     *
 *===========================================================================*/
static void hw_init(struct port *pp, int devind)
{
    u8_t v8;
    u16_t v16;
    u32_t v32;
#if USE_INTS
    int r, irq;
#endif

    pp->p_devind= devind;
    if (debug)
        printf("hw_init: devind = %d\n", devind);

    if (debug)
    {
        v16= pci_attr_r16(devind, PCI_CR);
        printf("ti1225: command register 0x%x\n", v16);
    }

    v32= pci_attr_r32(devind, TI_CB_BASEADDR);
    if (debug)
        printf("ti1225: Cardbus/ExCA base address 0x%x\n", v32);
    v32 &= PCI_BAR_MEM_MASK;	/* Clear low order bits in base */

    pp->csr_ptr=
        (struct csr *) vm_map_phys(SELF, (void *) v32, I386_PAGE_SIZE);
    if (pp->csr_ptr == MAP_FAILED)
        panic("hw_init: vm_map_phys failed");

    if (debug)
    {
        v8= pci_attr_r8(devind, TI_PCI_BUS_NR);
        printf("ti1225: PCI bus number %d\n", v8);
    }
    v8= pci_attr_r8(devind, TI_CB_BUS_NR);
    pp->p_cb_busnr= v8;
    if (debug)
    {
        printf("ti1225: CardBus bus number %d\n", v8);
        v8= pci_attr_r8(devind, TI_SO_BUS_NR);
        printf("ti1225: Subordinate bus number %d\n", v8);
    }

#if USE_INTS
    irq= pci_attr_r8(devind, PCI_ILR);
    pp->p_irq= irq;
    printf("ti1225 using IRQ %d\n", irq);
#endif

    v32= pci_attr_r32(devind, TI_LEGACY_BA);
    v32 &= ~1;
    if (debug)
    {
        printf("ti1225: PC Card 16-bit legacy-mode base address 0x%x\n",
               v32);
    }

    if (v32 == 0)
        panic("bad legacy-mode base address: %d", v32);
    pp->p_exca_port= v32;

    if (debug)
    {
        v32= pci_attr_r32(devind, TI_MF_ROUTE);
        printf("ti1225: Multifunction routing 0x%08x\n", v32);
    }

#if USE_INTS
    pp->p_hook = pp->p_irq;
    r= sys_irqsetpolicy(pp->p_irq, 0, &pp->p_hook);
    if (r != OK)
        panic("sys_irqsetpolicy failed: %d", r);
#endif

    /* Clear CBB_BC_INTEXCA */
    v16= pci_attr_r16(devind, CBB_BRIDGECTRL);
    if (debug)
        printf("ti1225: Bridge control 0x%04x\n", v16);
    v16 &= ~CBB_BC_INTEXCA;
    pci_attr_w16(devind, CBB_BRIDGECTRL, v16);

    if (debug)
    {
        v32= pci_attr_r32(devind, TI_SYSCTRL);
        printf("ti1225: System Control Register 0x%08x\n", v32);

        v8= pci_attr_r8(devind, TI_CARD_CTRL);
        printf("ti1225: Card Control 0x%02x\n", v8);

        v8= pci_attr_r8(devind, TI_DEV_CTRL);
        printf("ti1225: Device Control 0x%02x\n", v8);
    }

    /* Enable socket interrupts */
    pp->csr_ptr->csr_mask |= CM_PWRMASK | CM_CDMASK | CM_CSTSMASK;

    do_int(pp);

#if USE_INTS
    r= sys_irqenable(&pp->p_hook);
    if (r != OK)
        panic("unable enable interrupts: %d", r);
#endif
}
Ejemplo n.º 21
0
/*===========================================================================*
 *				do_int					     *
 *===========================================================================*/
static void do_int(struct port *pp)
{
    int devind, vcc_5v, vcc_3v, vcc_Xv, vcc_Yv,
        socket_5v, socket_3v, socket_Xv, socket_Yv;
    spin_t spin;
    u32_t csr_event, csr_present, csr_control;
    u8_t v8;
    u16_t v16;
#if USE_INTS
    int r;
#endif

    devind= pp->p_devind;
    v8= pci_attr_r8(devind, TI_CARD_CTRL);
    if (v8 & TI_CCR_IFG)
    {
        printf("ti1225: got functional interrupt\n");
        pci_attr_w8(devind, TI_CARD_CTRL, v8);
    }

    if (debug)
    {
        printf("Socket event: 0x%x\n", pp->csr_ptr->csr_event);
        printf("Socket mask: 0x%x\n", pp->csr_ptr->csr_mask);
    }

    csr_present= pp->csr_ptr->csr_present;
    csr_control= pp->csr_ptr->csr_control;

    if ((csr_present & (CP_CDETECT1|CP_CDETECT2)) != 0)
    {
        if (debug)
            printf("do_int: no card present\n");
        return;
    }
    if (csr_present & CP_BADVCCREQ)
    {
        printf("do_int: Bad Vcc request\n");
        /* return; */
    }
    if (csr_present & CP_DATALOST)
    {
        /* Do we care? */
        if (debug)
            printf("do_int: Data lost\n");
        /* return; */
    }
    if (csr_present & CP_NOTACARD)
    {
        printf("do_int: Not a card\n");
        return;
    }
    if (debug)
    {
        if (csr_present & CP_CBCARD)
            printf("do_int: Cardbus card detected\n");
        if (csr_present & CP_16BITCARD)
            printf("do_int: 16-bit card detected\n");
    }
    if (csr_present & CP_PWRCYCLE)
    {
        if (debug)
            printf("do_int: powered up\n");
        return;
    }
    vcc_5v= !!(csr_present & CP_5VCARD);
    vcc_3v= !!(csr_present & CP_3VCARD);
    vcc_Xv= !!(csr_present & CP_XVCARD);
    vcc_Yv= !!(csr_present & CP_YVCARD);
    if (debug)
    {
        printf("do_int: card supports:%s%s%s%s\n",
               vcc_5v ? " 5V" : "", vcc_3v ? " 3V" : "",
               vcc_Xv ? " X.X V" : "", vcc_Yv ? " Y.Y V" : "");
    }
    socket_5v= !!(csr_present & CP_5VSOCKET);
    socket_3v= !!(csr_present & CP_3VSOCKET);
    socket_Xv= !!(csr_present & CP_XVSOCKET);
    socket_Yv= !!(csr_present & CP_YVSOCKET);
    if (debug)
    {
        printf("do_int: socket supports:%s%s%s%s\n",
               socket_5v ? " 5V" : "", socket_3v ? " 3V" : "",
               socket_Xv ? " X.X V" : "", socket_Yv ? " Y.Y V" : "");
    }
    if (vcc_5v && socket_5v)
    {
        csr_control= (csr_control & ~CC_VCCCTRL) | CC_VCC_5V;
        pp->csr_ptr->csr_control= csr_control;
        if (debug)
            printf("do_int: applying 5V\n");
    }
    else if (vcc_3v && socket_3v)
    {
        csr_control= (csr_control & ~CC_VCCCTRL) | CC_VCC_3V;
        pp->csr_ptr->csr_control= csr_control;
        if (debug)
            printf("do_int: applying 3V\n");
    }
    else if (vcc_Xv && socket_Xv)
    {
        csr_control= (csr_control & ~CC_VCCCTRL) | CC_VCC_XV;
        pp->csr_ptr->csr_control= csr_control;
        printf("do_int: applying X.X V\n");
    }
    else if (vcc_Yv && socket_Yv)
    {
        csr_control= (csr_control & ~CC_VCCCTRL) | CC_VCC_YV;
        pp->csr_ptr->csr_control= csr_control;
        printf("do_int: applying Y.Y V\n");
    }
    else
    {
        printf("do_int: socket and card are not compatible\n");
        return;
    }

    csr_event= pp->csr_ptr->csr_event;
    if (csr_event)
    {
        if (debug)
            printf("clearing socket event\n");
        pp->csr_ptr->csr_event= csr_event;
        if (debug)
        {
            printf("Socket event (cleared): 0x%x\n",
                   pp->csr_ptr->csr_event);
        }
    }

    devind= pp->p_devind;
    v8= pci_attr_r8(devind, TI_CARD_CTRL);
    if (v8 & TI_CCR_IFG)
    {
        printf("ti1225: got functional interrupt\n");
        pci_attr_w8(devind, TI_CARD_CTRL, v8);
    }

    if (debug)
    {
        v8= pci_attr_r8(devind, TI_CARD_CTRL);
        printf("TI_CARD_CTRL: 0x%02x\n", v8);
    }

    spin_init(&spin, 100000);
    do {
        csr_present= pp->csr_ptr->csr_present;
        if (csr_present & CP_PWRCYCLE)
            break;
    } while (spin_check(&spin));

    if (!(csr_present & CP_PWRCYCLE))
    {
        printf("do_int: not powered up?\n");
        return;
    }

    /* Reset device */
    v16= pci_attr_r16(devind, CBB_BRIDGECTRL);
    v16 |= CBB_BC_CRST;
    pci_attr_w16(devind, CBB_BRIDGECTRL, v16);

    /* Wait one microsecond. Is this correct? What are the specs? */
    micro_delay(1);

    /* Clear CBB_BC_CRST */
    v16= pci_attr_r16(devind, CBB_BRIDGECTRL);
    v16 &= ~CBB_BC_CRST;
    pci_attr_w16(devind, CBB_BRIDGECTRL, v16);

    /* Wait one microsecond after clearing the reset line. Is this
     * correct? What are the specs?
     */
    micro_delay(1);

    pci_rescan_bus(pp->p_cb_busnr);

#if USE_INTS
    r= sys_irqenable(&pp->p_hook);
    if (r != OK)
        panic("unable enable interrupts: %d", r);
#endif

}
Ejemplo n.º 22
0
int kbd_subscribe_int(void) { //
	int value = KBD_HOOK_ID;
	sys_irqsetpolicy(IRQ1, IRQ_REENABLE | IRQ_EXCLUSIVE, &value);
	sys_irqenable(&value);
	return BIT(KBD_HOOK_ID);
}
Ejemplo n.º 23
0
/*===========================================================================*
 *				dpeth_task				     *
 *===========================================================================*/
int main(int argc, char *argv[])
{
	message m;
	int i, irq, r;
	dpeth_t *dep;
	long v;

	env_setargs(argc, argv);

	for (i= 0, dep= de_table; i<DE_PORT_NR; i++, dep++)
	{
		strcpy(dep->de_name, "dp8390#0");
		dep->de_name[7] += i;
	}

	v= 0;
	(void) env_parse("ETH_IGN_PROTO", "x", 0, &v, 0x0000L, 0xFFFFL);
	eth_ign_proto= htons((u16_t) v);

	while (TRUE)
	{
		if ((r= receive(ANY, &m)) != OK)
			panic("", "dp8390: receive failed", r);

		switch (m.m_type)
		{
		case DL_WRITE:	do_vwrite(&m, FALSE, FALSE);	break;
		case DL_WRITEV:	do_vwrite(&m, FALSE, TRUE);	break;
		case DL_READ:	do_vread(&m, FALSE);		break;
		case DL_READV:	do_vread(&m, TRUE);		break;
		case DL_INIT:	do_init(&m);			break;
		case DL_GETSTAT: do_getstat(&m);		break;
		case DL_STOP:	do_stop(&m);			break;
		case HARD_INT:
			for (i= 0, dep= &de_table[0]; i<DE_PORT_NR; i++, dep++)
			{
				if (dep->de_mode != DEM_ENABLED)
					continue;
				assert(dep->de_flags & DEF_ENABLED);
				irq= dep->de_irq;
				assert(irq >= 0 && irq < NR_IRQ_VECTORS);
				if (dep->de_int_pending || 1)
				{
					dep->de_int_pending= 0;
					dp_check_ints(dep);
					do_int(dep);
					r= sys_irqenable(&dep->de_hook);
					if (r != OK)
					{
						panic("DP8390", 
						"unable enable interrupts", r);
					}
				}
			}
			break;
		case SYS_SIG:	{
			sigset_t sigset = m.NOTIFY_ARG;
			if (sigismember(&sigset, SIGKSTOP)) dp8390_stop();
			break;
		}
		case SYN_ALARM:
			printf("dp8390: strange, got SYN_ALARM\n");
			break;
		default:
			panic("", "dp8390: illegal message", m.m_type);
		}
	}
}
Ejemplo n.º 24
0
/*===========================================================================*
 *				printer_intr				     *
 *===========================================================================*/
static void printer_intr(unsigned int UNUSED(mask))
{
/* This function does the actual output to the printer. This is called on an
 * interrupt message sent from the generic interrupt handler that 'forwards'
 * interrupts to this driver. The generic handler did not reenable the printer
 * IRQ yet! 
 */

  u32_t status;
  pvb_pair_t char_out[3];

  if (oleft == 0) {
	/* Nothing more to print.  Turn off printer interrupts in case they
	 * are level-sensitive as on the PS/2.  This should be safe even
	 * when the printer is busy with a previous character, because the
	 * interrupt status does not affect the printer.
	 */
	if(sys_outb(port_base + 2, PR_SELECT) != OK) {
		printf("printer: sys_outb of %x failed\n", port_base+2);
		panic("sys_outb failed");
	}
	if(sys_irqenable(&irq_hook_id) != OK) {
		panic("sys_irqenable failed");
	}
	return;
  }

  do {
	/* Loop to handle fast (buffered) printers.  It is important that
	 * processor interrupts are not disabled here, just printer interrupts.
	 */
	if(sys_inb(port_base + 1, &status) != OK) {
		printf("printer: sys_inb of %x failed\n", port_base+1);
		panic("sys_inb failed");
	}
	if ((status & STATUS_MASK) == BUSY_STATUS) {
		/* Still busy with last output.  This normally happens
		 * immediately after doing output to an unbuffered or slow
		 * printer.  It may happen after a call from prepare_output or
		 * pr_restart, since they are not synchronized with printer
		 * interrupts.  It may happen after a spurious interrupt.
		 */
		if(sys_irqenable(&irq_hook_id) != OK) {
			panic("sys_irqenable failed");
		}
		return;
	}
	if ((status & STATUS_MASK) == NORMAL_STATUS) {
		/* Everything is all right.  Output another character. */
		pv_set(char_out[0], port_base, *optr);	
		optr++;
		pv_set(char_out[1], port_base+2, ASSERT_STROBE);
		pv_set(char_out[2], port_base+2, NEGATE_STROBE);
		if(sys_voutb(char_out, 3) != OK) {
			/* request series of port outb */
			panic("sys_voutb failed");
		}

		user_vir_d++;
		user_left--;
	} else {
		/* Error.  This would be better ignored (treat as busy). */
		done_status = status;
		output_done();
		if(sys_irqenable(&irq_hook_id) != OK) {
			panic("sys_irqenable failed");
		}
		return;
	}
  }
  while (--oleft != 0);

  /* Finished printing chunk OK. */
  done_status = OK;
  output_done();
  if(sys_irqenable(&irq_hook_id) != OK) {
	panic("sys_irqenable failed");
  }
}
Ejemplo n.º 25
0
int rtc_subscribe_int(void ) {

	sys_irqsetpolicy(8, IRQ_REENABLE|IRQ_EXCLUSIVE, &hook);
	sys_irqenable(&hook);
	return 1;
}
Ejemplo n.º 26
0
PRIVATE void data_from_user(sub_dev_t *subdev)
{
	int r;
	message m;

	if (subdev->DmaLength == subdev->NrOfDmaFragments &&
			subdev->BufLength == subdev->NrOfExtraBuffers) return;/* no space */

	if (!subdev->RevivePending) return; /* no new data waiting to be copied */

	if (subdev->RevivePending && 
			subdev->ReadyToRevive) return; /* we already got this data */

	if (subdev->DmaLength < subdev->NrOfDmaFragments) { /* room in dma buf */

		sys_safecopyfrom(subdev->ReviveProcNr, 
				(vir_bytes)subdev->ReviveGrant, 0, 
				(vir_bytes)subdev->DmaPtr + 
				subdev->DmaFillNext * subdev->FragSize,
				(phys_bytes)subdev->FragSize, D);


		dprint(" user -> dma[%d]\n", subdev->DmaFillNext);
		subdev->DmaLength += 1;
		subdev->DmaFillNext = 
			(subdev->DmaFillNext + 1) % subdev->NrOfDmaFragments;

	} else { /* room in extra buf */ 

		sys_safecopyfrom(subdev->ReviveProcNr, 
				(vir_bytes)subdev->ReviveGrant, 0,
				(vir_bytes)subdev->ExtraBuf + 
				subdev->BufFillNext * subdev->FragSize, 
				(phys_bytes)subdev->FragSize, D);

		dprint(" user -> buf[%d]\n", subdev->BufFillNext);
		subdev->BufLength += 1;

		subdev->BufFillNext = 
			(subdev->BufFillNext + 1) % subdev->NrOfExtraBuffers;

	}
	if(subdev->OutOfData) { /* if device paused (because of lack of data) */
		subdev->OutOfData = FALSE;
		drv_reenable_int(subdev->Nr);
		/* reenable irq_hook*/
		if ((sys_irqenable(&irq_hook_id)) != OK) {
			error("%s: Couldn't enable IRQ", drv.DriverName);
		}
		drv_resume(subdev->Nr);  /* resume resume the sub device */
	}

	subdev->ReviveStatus = subdev->FragSize;
	subdev->ReadyToRevive = TRUE;

	m.m_type = DEV_REVIVE;			/* build message */
	m.REP_ENDPT = subdev->ReviveProcNr;
	m.REP_IO_GRANT = subdev->ReviveGrant;
	m.REP_STATUS = subdev->ReviveStatus;
	r= send(subdev->NotifyProcNr, &m);		/* send the message */
	if (r != OK)
	{
		printf("audio_fw: send to %d failed: %d\n",
			subdev->NotifyProcNr, r);
	}

	/* reset variables */
	subdev->ReadyToRevive = FALSE;
	subdev->RevivePending = 0;
}
Ejemplo n.º 27
0
int timer_subscribe_int(void) {
	hook_id = HOOK_ID;
	sys_irqsetpolicy(TIMER0_IRQ, IRQ_REENABLE, &hook_id); //used to subscribe a notification on every interrupt in the input TIMER0_IRQ
	sys_irqenable(&hook_id); //enables interrupts on the IRQ line associated with the specified hook_id
	return BIT(HOOK_ID);
}
Ejemplo n.º 28
0
/*===========================================================================*
 *                              main                                         *
 *===========================================================================*/
int main( int argc, char **argv )
{
   message m;
   int ipc_status;
   int r;
   ether_card_t *ec;

   /* SEF local startup. */
   env_setargs(argc, argv);
   sef_local_startup();

   ec= &ec_state;

   while (TRUE)
   {
      if (ec->ec_irq != 0)
         sys_irqenable(&ec->ec_hook);

      if ((r= netdriver_receive(ANY, &m, &ipc_status)) != OK)
        panic("netdriver_receive failed: %d", r);
        
      if (ec->ec_irq != 0)
         sys_irqdisable(&ec->ec_hook);

      if (is_ipc_notify(ipc_status)) {
	      switch(_ENDPOINT_P(m.m_source)) {
		      case TTY_PROC_NR:
			      lance_dump();
			      break;
		      case HARDWARE:
			      if (ec->mode == EC_ENABLED)
			      {
				 ec->ec_int_pending = 0;
				 ec_check_ints(ec);
				 do_int(ec);
			      }
			      break;
		      default:
			      panic("illegal notify source: %d", m.m_source);
	      }

	      /* get next message */
	      continue;
      }
  
      switch (m.m_type)
      {
      case DL_WRITEV_S:
         do_vwrite_s(&m, FALSE);
         break;
      case DL_READV_S:
         do_vread_s(&m);
         break;
      case DL_CONF:
         do_init(&m);
         break;
      case DL_GETSTAT_S:
         do_getstat_s(&m);
         break;
      default:
         panic("illegal message: %d", m.m_type);
      }
   }

   return 0;
}
Ejemplo n.º 29
0
int kbd_subscribe_int(void )
{
	if( sys_irqsetpolicy(KBD_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, &hook) == OK && sys_irqenable(&hook) == OK)
			return 1 << 0;
		return -1;
}
Ejemplo n.º 30
0
int timer_subscribe_int(void ) {
	timer_hook = 0;
	if(sys_irqsetpolicy(TIMER0_IRQ, IRQ_REENABLE,&timer_hook) == OK && sys_irqenable(&timer_hook) == OK)
		return 1 << 0;
	return -1;
}