diff options
author | John Baldwin <jhb@FreeBSD.org> | 2001-03-28 03:06:10 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2001-03-28 03:06:10 +0000 |
commit | 0006681fe6b5ffaa4658d592e020d3a0c3594147 (patch) | |
tree | db8d42c59fad73ff2c5df7452130bc4d7ef64cc6 | |
parent | b944b9033a951dd2202bb5c7d6f304d5ea09199e (diff) | |
download | src-0006681fe6b5ffaa4658d592e020d3a0c3594147.tar.gz src-0006681fe6b5ffaa4658d592e020d3a0c3594147.zip |
Switch from save/disable/restore_intr() to critical_enter/exit().
Notes
Notes:
svn path=/head/; revision=74903
-rw-r--r-- | sys/alpha/pci/cia.c | 15 | ||||
-rw-r--r-- | sys/amd64/amd64/db_interface.c | 12 | ||||
-rw-r--r-- | sys/amd64/amd64/fpu.c | 29 | ||||
-rw-r--r-- | sys/amd64/amd64/initcpu.c | 7 | ||||
-rw-r--r-- | sys/amd64/isa/npx.c | 29 | ||||
-rw-r--r-- | sys/dev/bktr/bktr_os.h | 6 | ||||
-rw-r--r-- | sys/dev/cy/cy.c | 177 | ||||
-rw-r--r-- | sys/dev/cy/cy_isa.c | 177 | ||||
-rw-r--r-- | sys/dev/sound/isa/mpu.c | 11 | ||||
-rw-r--r-- | sys/i386/i386/db_interface.c | 12 | ||||
-rw-r--r-- | sys/i386/i386/initcpu.c | 7 | ||||
-rw-r--r-- | sys/i386/i386/perfmon.c | 21 | ||||
-rw-r--r-- | sys/i386/isa/cy.c | 177 | ||||
-rw-r--r-- | sys/i386/isa/npx.c | 29 | ||||
-rw-r--r-- | sys/ia64/ia64/pmap.c | 7 | ||||
-rw-r--r-- | sys/kern/kern_ktr.c | 8 | ||||
-rw-r--r-- | sys/kern/subr_prof.c | 7 | ||||
-rw-r--r-- | sys/pc98/pc98/npx.c | 29 |
18 files changed, 343 insertions, 417 deletions
diff --git a/sys/alpha/pci/cia.c b/sys/alpha/pci/cia.c index b7b8eb725b17..34e0fb4ea29f 100644 --- a/sys/alpha/pci/cia.c +++ b/sys/alpha/pci/cia.c @@ -155,13 +155,14 @@ cia_swiz_set_hae_mem(void *arg, u_int32_t pa) * Seems fairly paranoid but this is what Linux does... */ u_int32_t msb = pa & REG1; - int s = save_intr(); - disable_intr(); + critical_t s; + + s = critical_enter(); cia_hae_mem = (cia_hae_mem & ~REG1) | msb; REGVAL(CIA_CSR_HAE_MEM) = cia_hae_mem; alpha_mb(); cia_hae_mem = REGVAL(CIA_CSR_HAE_MEM); - restore_intr(s); + critical_exit(s); } return pa & ~REG1; } @@ -227,10 +228,10 @@ cia_sgmap_invalidate_pyxis(void) { volatile u_int64_t dummy; u_int32_t ctrl; - int i, s; + int i; + critical_t s; - s = save_intr(); - disable_intr(); + s = critical_enter(); /* * Put the Pyxis into PCI loopback mode. @@ -261,7 +262,7 @@ cia_sgmap_invalidate_pyxis(void) REGVAL(CIA_CSR_CTRL) = ctrl; alpha_mb(); - restore_intr(s); + critical_exit(s); } static void diff --git a/sys/amd64/amd64/db_interface.c b/sys/amd64/amd64/db_interface.c index ee4ab194d173..ea2b8625cc74 100644 --- a/sys/amd64/amd64/db_interface.c +++ b/sys/amd64/amd64/db_interface.c @@ -309,7 +309,8 @@ Debugger(msg) const char *msg; { static volatile u_int in_Debugger; - int flags; + critical_t savecrit; + /* * XXX * Do nothing if the console is in graphics mode. This is @@ -319,12 +320,11 @@ Debugger(msg) if (cons_unavail && !(boothowto & RB_GDB)) return; - if (atomic_cmpset_int(&in_Debugger, 0, 1)) { - flags = save_intr(); - disable_intr(); + if (atomic_cmpset_acq_int(&in_Debugger, 0, 1)) { + savecrit = critical_enter(); db_printf("Debugger(\"%s\")\n", msg); breakpoint(); - restore_intr(flags); - in_Debugger = 0; + critical_exit(savecrit); + atomic_store_rel_int(&in_Debugger, 0); } } diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c index 285612355cf6..56e23a02d6d2 100644 --- a/sys/amd64/amd64/fpu.c +++ b/sys/amd64/amd64/fpu.c @@ -220,7 +220,7 @@ npx_probe(dev) #else /* SMP */ int result; - u_long save_eflags; + critical_t savecrit; u_char save_icu1_mask; u_char save_icu2_mask; struct gate_descriptor save_idt_npxintr; @@ -235,8 +235,7 @@ npx_probe(dev) if (resource_int_value("npx", 0, "irq", &npx_irq) != 0) npx_irq = 13; npx_intrno = NRSVIDT + npx_irq; - save_eflags = read_eflags(); - disable_intr(); + savecrit = critical_enter(); save_icu1_mask = inb(IO_ICU1 + 1); save_icu2_mask = inb(IO_ICU2 + 1); save_idt_npxintr = idt[npx_intrno]; @@ -252,14 +251,14 @@ npx_probe(dev) * needs interrupts enabled. Does this make any difference * here? */ - enable_intr(); + critical_exit(savecrit); result = npx_probe1(dev); - disable_intr(); + savecrit = critical_enter(); outb(IO_ICU1 + 1, save_icu1_mask); outb(IO_ICU2 + 1, save_icu2_mask); idt[npx_intrno] = save_idt_npxintr; idt[16] = save_idt_npxtrap; - write_eflags(save_eflags); + critical_exit(savecrit); return (result); #endif /* SMP */ @@ -798,7 +797,7 @@ npx_intr(dummy) int npxdna() { - int s; + critical_t s; if (!npx_exists) return (0); @@ -807,8 +806,7 @@ npxdna() PCPU_GET(npxproc), curproc); panic("npxdna"); } - s = save_intr(); - disable_intr(); + s = critical_enter(); stop_emulating(); /* * Record new context early in case frstor causes an IRQ13. @@ -828,7 +826,7 @@ npxdna() * first FPU instruction after a context switch. */ frstor(&PCPU_GET(curpcb)->pcb_savefpu); - restore_intr(s); + critical_exit(s); return (1); } @@ -855,28 +853,27 @@ npxsave(addr) #else /* SMP */ - int intrstate; + critical_t savecrit; u_char icu1_mask; u_char icu2_mask; u_char old_icu1_mask; u_char old_icu2_mask; struct gate_descriptor save_idt_npxintr; - intrstate = save_intr(); - disable_intr(); + savecrit = critical_enter(); old_icu1_mask = inb(IO_ICU1 + 1); old_icu2_mask = inb(IO_ICU2 + 1); save_idt_npxintr = idt[npx_intrno]; outb(IO_ICU1 + 1, old_icu1_mask & ~(IRQ_SLAVE | npx0_imask)); outb(IO_ICU2 + 1, old_icu2_mask & ~(npx0_imask >> 8)); idt[npx_intrno] = npx_idt_probeintr; - write_eflags(intrstate); + critical_exit(savecrit); stop_emulating(); fnsave(addr); fnop(); start_emulating(); + savecrit = critical_enter(); PCPU_SET(npxproc, NULL); - disable_intr(); icu1_mask = inb(IO_ICU1 + 1); /* masks may have changed */ icu2_mask = inb(IO_ICU2 + 1); outb(IO_ICU1 + 1, @@ -885,7 +882,7 @@ npxsave(addr) (icu2_mask & ~(npx0_imask >> 8)) | (old_icu2_mask & (npx0_imask >> 8))); idt[npx_intrno] = save_idt_npxintr; - restore_intr(intrstate); /* back to previous state */ + critical_exit(savecrit); /* back to previous state */ #endif /* SMP */ } diff --git a/sys/amd64/amd64/initcpu.c b/sys/amd64/amd64/initcpu.c index b42c234d36da..8b39b447a7a8 100644 --- a/sys/amd64/amd64/initcpu.c +++ b/sys/amd64/amd64/initcpu.c @@ -607,15 +607,14 @@ void enable_K5_wt_alloc(void) { u_int64_t msr; - int intrstate; + critical_t savecrit; /* * Write allocate is supported only on models 1, 2, and 3, with * a stepping of 4 or greater. */ if (((cpu_id & 0xf0) > 0) && ((cpu_id & 0x0f) > 3)) { - intrstate = save_intr(); - disable_intr(); + savecrit = critical_enter(); msr = rdmsr(0x83); /* HWCR */ wrmsr(0x83, msr & !(0x10)); @@ -647,7 +646,7 @@ enable_K5_wt_alloc(void) msr=rdmsr(0x83); wrmsr(0x83, msr|0x10); /* enable write allocate */ - restore_intr(intrstate); + critical_exit(savecrit); } } diff --git a/sys/amd64/isa/npx.c b/sys/amd64/isa/npx.c index 285612355cf6..56e23a02d6d2 100644 --- a/sys/amd64/isa/npx.c +++ b/sys/amd64/isa/npx.c @@ -220,7 +220,7 @@ npx_probe(dev) #else /* SMP */ int result; - u_long save_eflags; + critical_t savecrit; u_char save_icu1_mask; u_char save_icu2_mask; struct gate_descriptor save_idt_npxintr; @@ -235,8 +235,7 @@ npx_probe(dev) if (resource_int_value("npx", 0, "irq", &npx_irq) != 0) npx_irq = 13; npx_intrno = NRSVIDT + npx_irq; - save_eflags = read_eflags(); - disable_intr(); + savecrit = critical_enter(); save_icu1_mask = inb(IO_ICU1 + 1); save_icu2_mask = inb(IO_ICU2 + 1); save_idt_npxintr = idt[npx_intrno]; @@ -252,14 +251,14 @@ npx_probe(dev) * needs interrupts enabled. Does this make any difference * here? */ - enable_intr(); + critical_exit(savecrit); result = npx_probe1(dev); - disable_intr(); + savecrit = critical_enter(); outb(IO_ICU1 + 1, save_icu1_mask); outb(IO_ICU2 + 1, save_icu2_mask); idt[npx_intrno] = save_idt_npxintr; idt[16] = save_idt_npxtrap; - write_eflags(save_eflags); + critical_exit(savecrit); return (result); #endif /* SMP */ @@ -798,7 +797,7 @@ npx_intr(dummy) int npxdna() { - int s; + critical_t s; if (!npx_exists) return (0); @@ -807,8 +806,7 @@ npxdna() PCPU_GET(npxproc), curproc); panic("npxdna"); } - s = save_intr(); - disable_intr(); + s = critical_enter(); stop_emulating(); /* * Record new context early in case frstor causes an IRQ13. @@ -828,7 +826,7 @@ npxdna() * first FPU instruction after a context switch. */ frstor(&PCPU_GET(curpcb)->pcb_savefpu); - restore_intr(s); + critical_exit(s); return (1); } @@ -855,28 +853,27 @@ npxsave(addr) #else /* SMP */ - int intrstate; + critical_t savecrit; u_char icu1_mask; u_char icu2_mask; u_char old_icu1_mask; u_char old_icu2_mask; struct gate_descriptor save_idt_npxintr; - intrstate = save_intr(); - disable_intr(); + savecrit = critical_enter(); old_icu1_mask = inb(IO_ICU1 + 1); old_icu2_mask = inb(IO_ICU2 + 1); save_idt_npxintr = idt[npx_intrno]; outb(IO_ICU1 + 1, old_icu1_mask & ~(IRQ_SLAVE | npx0_imask)); outb(IO_ICU2 + 1, old_icu2_mask & ~(npx0_imask >> 8)); idt[npx_intrno] = npx_idt_probeintr; - write_eflags(intrstate); + critical_exit(savecrit); stop_emulating(); fnsave(addr); fnop(); start_emulating(); + savecrit = critical_enter(); PCPU_SET(npxproc, NULL); - disable_intr(); icu1_mask = inb(IO_ICU1 + 1); /* masks may have changed */ icu2_mask = inb(IO_ICU2 + 1); outb(IO_ICU1 + 1, @@ -885,7 +882,7 @@ npxsave(addr) (icu2_mask & ~(npx0_imask >> 8)) | (old_icu2_mask & (npx0_imask >> 8))); idt[npx_intrno] = save_idt_npxintr; - restore_intr(intrstate); /* back to previous state */ + critical_exit(savecrit); /* back to previous state */ #endif /* SMP */ } diff --git a/sys/dev/bktr/bktr_os.h b/sys/dev/bktr/bktr_os.h index 2e1ff269c409..21d3f602e38a 100644 --- a/sys/dev/bktr/bktr_os.h +++ b/sys/dev/bktr/bktr_os.h @@ -60,9 +60,15 @@ void free_bktr_mem(bktr_ptr_t, bus_dmamap_t, vm_offset_t); /* *** Interrupt Enable/Disable *** */ /************************************/ #if defined(__FreeBSD__) +#if (__FreeBSD_version >=500000) +#define DECLARE_INTR_MASK(s) critical_t s +#define DISABLE_INTR(s) s = critical_enter() +#define ENABLE_INTR(s) critical_exit(s) +#else #define DECLARE_INTR_MASK(s) intrmask_t s #define DISABLE_INTR(s) s=spltty() #define ENABLE_INTR(s) splx(s) +#endif #else #define DECLARE_INTR_MASK(s) /* no need to declare 's' */ #define DISABLE_INTR(s) disable_intr() diff --git a/sys/dev/cy/cy.c b/sys/dev/cy/cy.c index f5161a6f4eb3..6f4aaf654c9f 100644 --- a/sys/dev/cy/cy.c +++ b/sys/dev/cy/cy.c @@ -350,7 +350,7 @@ static int cd_getreg __P((struct com_s *com, int reg)); static void cd_setreg __P((struct com_s *com, int reg, int val)); static timeout_t siodtrwakeup; static void comhardclose __P((struct com_s *com)); -static void sioinput __P((struct com_s *com)); +static void sioinput __P((struct com_s *com, critical_t *savecrit)); #if 0 static void siointr1 __P((struct com_s *com)); #endif @@ -672,7 +672,7 @@ sioopen(dev, flag, mode, p) int s; struct tty *tp; int unit; - int intrsave; + critical_t savecrit; mynor = minor(dev); unit = MINOR_TO_UNIT(mynor); @@ -779,8 +779,7 @@ open_top: } } - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); (void) inb(com->line_status_port); (void) inb(com->data_port); @@ -789,7 +788,7 @@ open_top: outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY | IER_ERLS | IER_EMSC); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); #else /* !0 */ /* * Flush fifos. This requires a full channel reset which @@ -800,8 +799,7 @@ open_top: CD1400_CCR_CMDRESET | CD1400_CCR_CHANRESET); cd1400_channel_cmd(com, com->channel_control); - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com->prev_modem_status = com->last_modem_status = cd_getreg(com, CD1400_MSVR2); @@ -809,7 +807,7 @@ open_top: com->intr_enable = CD1400_SRER_MDMCH | CD1400_SRER_RXDATA); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); #endif /* 0 */ /* * Handle initial DCD. Callout devices get a fake initial @@ -892,7 +890,7 @@ comhardclose(com) int s; struct tty *tp; int unit; - int intrsave; + critical_t savecrit; unit = com->unit; iobase = com->iobase; @@ -906,13 +904,12 @@ comhardclose(com) outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK); #else /* XXX */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com->etc = ETC_NONE; cd_setreg(com, CD1400_COR2, com->cor[1] &= ~CD1400_COR2_ETC); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF); #endif @@ -920,12 +917,11 @@ comhardclose(com) #if 0 outb(iobase + com_ier, 0); #else - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); cd_setreg(com, CD1400_SRER, com->intr_enable = 0); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); #endif tp = com->tp; if ((tp->t_cflag & HUPCL) @@ -1021,15 +1017,15 @@ siodtrwakeup(chan) * b) needs to return with COM_LOCK() held. */ static void -sioinput(com) +sioinput(com, savecrit) struct com_s *com; + critical_t *savecrit; { u_char *buf; int incc; u_char line_status; int recv_data; struct tty *tp; - int intrsave; buf = com->ibuf; tp = com->tp; @@ -1053,9 +1049,8 @@ sioinput(com) * semantics instead of the save-and-disable semantics * that are used everywhere else. */ - intrsave = save_intr(); COM_UNLOCK(); - enable_intr(); + critical_exit(*savecrit); incc = com->iptr - buf; if (tp->t_rawq.c_cc + incc > tp->t_ihiwat && (com->state & CS_RTS_IFLOW @@ -1076,7 +1071,7 @@ sioinput(com) tp->t_lflag &= ~FLUSHO; comstart(tp); } - restore_intr(intrsave); + *savecrit = critical_enter(); COM_LOCK(); } while (buf < com->iptr); } else { @@ -1086,9 +1081,8 @@ sioinput(com) * semantics instead of the save-and-disable semantics * that are used everywhere else. */ - intrsave = save_intr(); COM_UNLOCK(); - enable_intr(); + critical_exit(*savecrit); line_status = buf[com->ierroff]; recv_data = *buf++; if (line_status @@ -1103,7 +1097,7 @@ sioinput(com) recv_data |= TTY_PE; } (*linesw[tp->t_line].l_rint)(recv_data, tp); - restore_intr(intrsave); + *savecrit = critical_enter(); COM_LOCK(); } while (buf < com->iptr); } @@ -1777,7 +1771,7 @@ static void siopoll(void *arg) { int unit; - int intrsave; + critical_t savecrit; #ifdef CyDebug ++cy_timeouts; @@ -1800,8 +1794,7 @@ repeat: * (actually never opened devices) so that we don't * loop. */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); incc = com->iptr - com->ibuf; com->iptr = com->ibuf; @@ -1811,7 +1804,7 @@ repeat: } com_events -= incc; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (incc != 0) log(LOG_DEBUG, "sio%d: %d events for device with no tp\n", @@ -1819,39 +1812,36 @@ repeat: continue; } if (com->iptr != com->ibuf) { - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); - sioinput(com); + sioinput(com, &savecrit); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } if (com->state & CS_CHECKMSR) { u_char delta_modem_status; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); - sioinput(com); + sioinput(com, &savecrit); delta_modem_status = com->last_modem_status ^ com->prev_modem_status; com->prev_modem_status = com->last_modem_status; com_events -= LOTS_OF_EVENTS; com->state &= ~CS_CHECKMSR; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (delta_modem_status & MSR_DCD) (*linesw[tp->t_line].l_modem) (tp, com->prev_modem_status & MSR_DCD); } if (com->extra_state & CSE_ODONE) { - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com_events -= LOTS_OF_EVENTS; com->extra_state &= ~CSE_ODONE; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (!(com->state & CS_BUSY)) { tp->t_state &= ~TS_BUSY; ttwwakeup(com->tp); @@ -1863,13 +1853,12 @@ repeat: } } if (com->state & CS_ODONE) { - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com_events -= LOTS_OF_EVENTS; com->state &= ~CS_ODONE; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); (*linesw[tp->t_line].l_start)(tp); } if (com_events == 0) @@ -1898,7 +1887,7 @@ comparam(tp, t) u_char opt; int s; int unit; - int intrsave; + critical_t savecrit; /* do historical conversions */ if (t->c_ispeed == 0) @@ -2046,15 +2035,14 @@ comparam(tp, t) if (cflag & CCTS_OFLOW) opt |= CD1400_COR2_CCTS_OFLOW; #endif - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (opt != com->cor[1]) { cor_change |= CD1400_CCR_COR2; cd_setreg(com, CD1400_COR2, com->cor[1] = opt); } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); /* * set channel option register 3 - @@ -2175,8 +2163,7 @@ comparam(tp, t) * XXX should have done this long ago, but there is too much state * to change all atomically. */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com->state &= ~CS_TTGO; @@ -2244,7 +2231,7 @@ comparam(tp, t) } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); splx(s); comstart(tp); if (com->ibufold != NULL) { @@ -2263,7 +2250,7 @@ siosetwater(com, speed) u_char *ibuf; int ibufsize; struct tty *tp; - int intrsave; + critical_t savecrit; /* * Make the buffer size large enough to handle a softtty interrupt @@ -2301,11 +2288,10 @@ siosetwater(com, speed) * Read current input buffer, if any. Continue with interrupts * disabled. */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->iptr != com->ibuf) - sioinput(com); + sioinput(com, &savecrit); /*- * Initialize critical variables, including input buffer watermarks. @@ -2324,7 +2310,7 @@ siosetwater(com, speed) com->ihighwater = ibuf + 3 * ibufsize / 4; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); return (0); } @@ -2338,7 +2324,7 @@ comstart(tp) bool_t started; #endif int unit; - int intrsave; + critical_t savecrit; unit = DEV_TO_UNIT(tp->t_dev); com = com_addr(unit); @@ -2349,8 +2335,7 @@ comstart(tp) started = FALSE; #endif - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (tp->t_state & TS_TTSTOP) { com->state &= ~CS_TTGO; @@ -2388,7 +2373,7 @@ comstart(tp) #endif } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) { ttwwakeup(tp); splx(s); @@ -2407,8 +2392,7 @@ comstart(tp) sizeof com->obuf1); com->obufs[0].l_next = NULL; com->obufs[0].l_queued = TRUE; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->state & CS_BUSY) { qp = com->obufq.l_next; @@ -2429,7 +2413,7 @@ comstart(tp) | CD1400_SRER_TXRDY); } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) { #ifdef CyDebug @@ -2440,8 +2424,7 @@ comstart(tp) sizeof com->obuf2); com->obufs[1].l_next = NULL; com->obufs[1].l_queued = TRUE; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->state & CS_BUSY) { qp = com->obufq.l_next; @@ -2462,7 +2445,7 @@ comstart(tp) | CD1400_SRER_TXRDY); } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } tp->t_state |= TS_BUSY; } @@ -2471,13 +2454,12 @@ comstart(tp) ++com->start_real; #endif #if 0 - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->state >= (CS_BUSY | CS_TTGO)) siointr1(com); /* fake interrupt to start output */ COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); #endif ttwwakeup(tp); splx(s); @@ -2490,12 +2472,11 @@ comstop(tp, rw) { struct com_s *com; bool_t wakeup_etc; - int intrsave; + critical_t savecrit; com = com_addr(DEV_TO_UNIT(tp->t_dev)); wakeup_etc = FALSE; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (rw & FWRITE) { com->obufs[0].l_queued = FALSE; @@ -2520,7 +2501,7 @@ comstop(tp, rw) com->iptr = com->ibuf; } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (wakeup_etc) wakeup(&com->etc); if (rw & FWRITE && com->etc == ETC_NONE) @@ -2536,7 +2517,7 @@ commctl(com, bits, how) { int mcr; int msr; - int intrsave; + critical_t savecrit; if (how == DMGET) { if (com->channel_control & CD1400_CCR_RCVEN) @@ -2574,8 +2555,7 @@ commctl(com, bits, how) mcr |= com->mcr_dtr; if (bits & TIOCM_RTS) mcr |= com->mcr_rts; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); switch (how) { case DMSET: @@ -2595,7 +2575,7 @@ commctl(com, bits, how) break; } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); return (0); } @@ -2657,14 +2637,13 @@ comwakeup(chan) com = com_addr(unit); if (com != NULL && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) { - int intrsave; + critical_t savecrit; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); siointr1(com); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } } #endif @@ -2684,15 +2663,14 @@ comwakeup(chan) for (errnum = 0; errnum < CE_NTYPES; ++errnum) { u_int delta; u_long total; - int intrsave; + critical_t savecrit; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); delta = com->delta_error_counts[errnum]; com->delta_error_counts[errnum] = 0; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (delta == 0) continue; total = com->error_counts[errnum] += delta; @@ -2844,7 +2822,7 @@ cd_etc(com, etc) struct com_s *com; int etc; { - int intrsave; + critical_t savecrit; /* * We can't change the hardware's ETC state while there are any @@ -2857,8 +2835,7 @@ cd_etc(com, etc) * for the tx to become empty so that the command is sure to be * executed soon after we issue it. */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->etc == etc) goto wait; @@ -2869,7 +2846,7 @@ cd_etc(com, etc) && (com->etc == ETC_BREAK_ENDING || com->etc == ETC_BREAK_ENDED || com->etc == ETC_NONE))) { COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); return; } com->etc = etc; @@ -2878,7 +2855,7 @@ cd_etc(com, etc) = (com->intr_enable & ~CD1400_SRER_TXRDY) | CD1400_SRER_TXMPTY); wait: COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); while (com->etc == etc && tsleep(&com->etc, TTIPRI | PCATCH, "cyetc", 0) == 0) continue; @@ -2892,7 +2869,8 @@ cd_getreg(com, reg) struct com_s *basecom; u_char car; int cy_align; - int intrsave; + criticale_t savecrit; + register_t eflags; cy_addr iobase; int val; @@ -2900,16 +2878,16 @@ cd_getreg(com, reg) car = com->unit & CD1400_CAR_CHAN; cy_align = com->cy_align; iobase = com->iobase; - intrsave = save_intr(); - disable_intr(); - if (intrsave & PSL_I) + eflags = read_eflags(); + savecrit = critical_enter(); + if (eflags & PSL_I) COM_LOCK(); if (basecom->car != car) cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car); val = cd_inb(iobase, reg, cy_align); - if (intrsave & PSL_I) + if (eflags & PSL_I) COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); return (val); } @@ -2922,23 +2900,24 @@ cd_setreg(com, reg, val) struct com_s *basecom; u_char car; int cy_align; - int intrsave; + critical_t savecrit; + register_t eflags; cy_addr iobase; basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1)); car = com->unit & CD1400_CAR_CHAN; cy_align = com->cy_align; iobase = com->iobase; - intrsave = save_intr(); - disable_intr(); - if (intrsave & PSL_I) + eflags = read_eflags(); + savecrit = critical_enter(); + if (eflags & PSL_I) COM_LOCK(); if (basecom->car != car) cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car); cd_outb(iobase, reg, cy_align, val); - if (intrsave & PSL_I) + if (eflags & PSL_I) COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } #ifdef CyDebug diff --git a/sys/dev/cy/cy_isa.c b/sys/dev/cy/cy_isa.c index f5161a6f4eb3..6f4aaf654c9f 100644 --- a/sys/dev/cy/cy_isa.c +++ b/sys/dev/cy/cy_isa.c @@ -350,7 +350,7 @@ static int cd_getreg __P((struct com_s *com, int reg)); static void cd_setreg __P((struct com_s *com, int reg, int val)); static timeout_t siodtrwakeup; static void comhardclose __P((struct com_s *com)); -static void sioinput __P((struct com_s *com)); +static void sioinput __P((struct com_s *com, critical_t *savecrit)); #if 0 static void siointr1 __P((struct com_s *com)); #endif @@ -672,7 +672,7 @@ sioopen(dev, flag, mode, p) int s; struct tty *tp; int unit; - int intrsave; + critical_t savecrit; mynor = minor(dev); unit = MINOR_TO_UNIT(mynor); @@ -779,8 +779,7 @@ open_top: } } - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); (void) inb(com->line_status_port); (void) inb(com->data_port); @@ -789,7 +788,7 @@ open_top: outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY | IER_ERLS | IER_EMSC); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); #else /* !0 */ /* * Flush fifos. This requires a full channel reset which @@ -800,8 +799,7 @@ open_top: CD1400_CCR_CMDRESET | CD1400_CCR_CHANRESET); cd1400_channel_cmd(com, com->channel_control); - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com->prev_modem_status = com->last_modem_status = cd_getreg(com, CD1400_MSVR2); @@ -809,7 +807,7 @@ open_top: com->intr_enable = CD1400_SRER_MDMCH | CD1400_SRER_RXDATA); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); #endif /* 0 */ /* * Handle initial DCD. Callout devices get a fake initial @@ -892,7 +890,7 @@ comhardclose(com) int s; struct tty *tp; int unit; - int intrsave; + critical_t savecrit; unit = com->unit; iobase = com->iobase; @@ -906,13 +904,12 @@ comhardclose(com) outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK); #else /* XXX */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com->etc = ETC_NONE; cd_setreg(com, CD1400_COR2, com->cor[1] &= ~CD1400_COR2_ETC); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF); #endif @@ -920,12 +917,11 @@ comhardclose(com) #if 0 outb(iobase + com_ier, 0); #else - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); cd_setreg(com, CD1400_SRER, com->intr_enable = 0); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); #endif tp = com->tp; if ((tp->t_cflag & HUPCL) @@ -1021,15 +1017,15 @@ siodtrwakeup(chan) * b) needs to return with COM_LOCK() held. */ static void -sioinput(com) +sioinput(com, savecrit) struct com_s *com; + critical_t *savecrit; { u_char *buf; int incc; u_char line_status; int recv_data; struct tty *tp; - int intrsave; buf = com->ibuf; tp = com->tp; @@ -1053,9 +1049,8 @@ sioinput(com) * semantics instead of the save-and-disable semantics * that are used everywhere else. */ - intrsave = save_intr(); COM_UNLOCK(); - enable_intr(); + critical_exit(*savecrit); incc = com->iptr - buf; if (tp->t_rawq.c_cc + incc > tp->t_ihiwat && (com->state & CS_RTS_IFLOW @@ -1076,7 +1071,7 @@ sioinput(com) tp->t_lflag &= ~FLUSHO; comstart(tp); } - restore_intr(intrsave); + *savecrit = critical_enter(); COM_LOCK(); } while (buf < com->iptr); } else { @@ -1086,9 +1081,8 @@ sioinput(com) * semantics instead of the save-and-disable semantics * that are used everywhere else. */ - intrsave = save_intr(); COM_UNLOCK(); - enable_intr(); + critical_exit(*savecrit); line_status = buf[com->ierroff]; recv_data = *buf++; if (line_status @@ -1103,7 +1097,7 @@ sioinput(com) recv_data |= TTY_PE; } (*linesw[tp->t_line].l_rint)(recv_data, tp); - restore_intr(intrsave); + *savecrit = critical_enter(); COM_LOCK(); } while (buf < com->iptr); } @@ -1777,7 +1771,7 @@ static void siopoll(void *arg) { int unit; - int intrsave; + critical_t savecrit; #ifdef CyDebug ++cy_timeouts; @@ -1800,8 +1794,7 @@ repeat: * (actually never opened devices) so that we don't * loop. */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); incc = com->iptr - com->ibuf; com->iptr = com->ibuf; @@ -1811,7 +1804,7 @@ repeat: } com_events -= incc; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (incc != 0) log(LOG_DEBUG, "sio%d: %d events for device with no tp\n", @@ -1819,39 +1812,36 @@ repeat: continue; } if (com->iptr != com->ibuf) { - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); - sioinput(com); + sioinput(com, &savecrit); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } if (com->state & CS_CHECKMSR) { u_char delta_modem_status; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); - sioinput(com); + sioinput(com, &savecrit); delta_modem_status = com->last_modem_status ^ com->prev_modem_status; com->prev_modem_status = com->last_modem_status; com_events -= LOTS_OF_EVENTS; com->state &= ~CS_CHECKMSR; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (delta_modem_status & MSR_DCD) (*linesw[tp->t_line].l_modem) (tp, com->prev_modem_status & MSR_DCD); } if (com->extra_state & CSE_ODONE) { - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com_events -= LOTS_OF_EVENTS; com->extra_state &= ~CSE_ODONE; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (!(com->state & CS_BUSY)) { tp->t_state &= ~TS_BUSY; ttwwakeup(com->tp); @@ -1863,13 +1853,12 @@ repeat: } } if (com->state & CS_ODONE) { - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com_events -= LOTS_OF_EVENTS; com->state &= ~CS_ODONE; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); (*linesw[tp->t_line].l_start)(tp); } if (com_events == 0) @@ -1898,7 +1887,7 @@ comparam(tp, t) u_char opt; int s; int unit; - int intrsave; + critical_t savecrit; /* do historical conversions */ if (t->c_ispeed == 0) @@ -2046,15 +2035,14 @@ comparam(tp, t) if (cflag & CCTS_OFLOW) opt |= CD1400_COR2_CCTS_OFLOW; #endif - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (opt != com->cor[1]) { cor_change |= CD1400_CCR_COR2; cd_setreg(com, CD1400_COR2, com->cor[1] = opt); } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); /* * set channel option register 3 - @@ -2175,8 +2163,7 @@ comparam(tp, t) * XXX should have done this long ago, but there is too much state * to change all atomically. */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com->state &= ~CS_TTGO; @@ -2244,7 +2231,7 @@ comparam(tp, t) } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); splx(s); comstart(tp); if (com->ibufold != NULL) { @@ -2263,7 +2250,7 @@ siosetwater(com, speed) u_char *ibuf; int ibufsize; struct tty *tp; - int intrsave; + critical_t savecrit; /* * Make the buffer size large enough to handle a softtty interrupt @@ -2301,11 +2288,10 @@ siosetwater(com, speed) * Read current input buffer, if any. Continue with interrupts * disabled. */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->iptr != com->ibuf) - sioinput(com); + sioinput(com, &savecrit); /*- * Initialize critical variables, including input buffer watermarks. @@ -2324,7 +2310,7 @@ siosetwater(com, speed) com->ihighwater = ibuf + 3 * ibufsize / 4; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); return (0); } @@ -2338,7 +2324,7 @@ comstart(tp) bool_t started; #endif int unit; - int intrsave; + critical_t savecrit; unit = DEV_TO_UNIT(tp->t_dev); com = com_addr(unit); @@ -2349,8 +2335,7 @@ comstart(tp) started = FALSE; #endif - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (tp->t_state & TS_TTSTOP) { com->state &= ~CS_TTGO; @@ -2388,7 +2373,7 @@ comstart(tp) #endif } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) { ttwwakeup(tp); splx(s); @@ -2407,8 +2392,7 @@ comstart(tp) sizeof com->obuf1); com->obufs[0].l_next = NULL; com->obufs[0].l_queued = TRUE; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->state & CS_BUSY) { qp = com->obufq.l_next; @@ -2429,7 +2413,7 @@ comstart(tp) | CD1400_SRER_TXRDY); } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) { #ifdef CyDebug @@ -2440,8 +2424,7 @@ comstart(tp) sizeof com->obuf2); com->obufs[1].l_next = NULL; com->obufs[1].l_queued = TRUE; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->state & CS_BUSY) { qp = com->obufq.l_next; @@ -2462,7 +2445,7 @@ comstart(tp) | CD1400_SRER_TXRDY); } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } tp->t_state |= TS_BUSY; } @@ -2471,13 +2454,12 @@ comstart(tp) ++com->start_real; #endif #if 0 - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->state >= (CS_BUSY | CS_TTGO)) siointr1(com); /* fake interrupt to start output */ COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); #endif ttwwakeup(tp); splx(s); @@ -2490,12 +2472,11 @@ comstop(tp, rw) { struct com_s *com; bool_t wakeup_etc; - int intrsave; + critical_t savecrit; com = com_addr(DEV_TO_UNIT(tp->t_dev)); wakeup_etc = FALSE; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (rw & FWRITE) { com->obufs[0].l_queued = FALSE; @@ -2520,7 +2501,7 @@ comstop(tp, rw) com->iptr = com->ibuf; } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (wakeup_etc) wakeup(&com->etc); if (rw & FWRITE && com->etc == ETC_NONE) @@ -2536,7 +2517,7 @@ commctl(com, bits, how) { int mcr; int msr; - int intrsave; + critical_t savecrit; if (how == DMGET) { if (com->channel_control & CD1400_CCR_RCVEN) @@ -2574,8 +2555,7 @@ commctl(com, bits, how) mcr |= com->mcr_dtr; if (bits & TIOCM_RTS) mcr |= com->mcr_rts; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); switch (how) { case DMSET: @@ -2595,7 +2575,7 @@ commctl(com, bits, how) break; } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); return (0); } @@ -2657,14 +2637,13 @@ comwakeup(chan) com = com_addr(unit); if (com != NULL && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) { - int intrsave; + critical_t savecrit; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); siointr1(com); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } } #endif @@ -2684,15 +2663,14 @@ comwakeup(chan) for (errnum = 0; errnum < CE_NTYPES; ++errnum) { u_int delta; u_long total; - int intrsave; + critical_t savecrit; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); delta = com->delta_error_counts[errnum]; com->delta_error_counts[errnum] = 0; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (delta == 0) continue; total = com->error_counts[errnum] += delta; @@ -2844,7 +2822,7 @@ cd_etc(com, etc) struct com_s *com; int etc; { - int intrsave; + critical_t savecrit; /* * We can't change the hardware's ETC state while there are any @@ -2857,8 +2835,7 @@ cd_etc(com, etc) * for the tx to become empty so that the command is sure to be * executed soon after we issue it. */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->etc == etc) goto wait; @@ -2869,7 +2846,7 @@ cd_etc(com, etc) && (com->etc == ETC_BREAK_ENDING || com->etc == ETC_BREAK_ENDED || com->etc == ETC_NONE))) { COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); return; } com->etc = etc; @@ -2878,7 +2855,7 @@ cd_etc(com, etc) = (com->intr_enable & ~CD1400_SRER_TXRDY) | CD1400_SRER_TXMPTY); wait: COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); while (com->etc == etc && tsleep(&com->etc, TTIPRI | PCATCH, "cyetc", 0) == 0) continue; @@ -2892,7 +2869,8 @@ cd_getreg(com, reg) struct com_s *basecom; u_char car; int cy_align; - int intrsave; + criticale_t savecrit; + register_t eflags; cy_addr iobase; int val; @@ -2900,16 +2878,16 @@ cd_getreg(com, reg) car = com->unit & CD1400_CAR_CHAN; cy_align = com->cy_align; iobase = com->iobase; - intrsave = save_intr(); - disable_intr(); - if (intrsave & PSL_I) + eflags = read_eflags(); + savecrit = critical_enter(); + if (eflags & PSL_I) COM_LOCK(); if (basecom->car != car) cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car); val = cd_inb(iobase, reg, cy_align); - if (intrsave & PSL_I) + if (eflags & PSL_I) COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); return (val); } @@ -2922,23 +2900,24 @@ cd_setreg(com, reg, val) struct com_s *basecom; u_char car; int cy_align; - int intrsave; + critical_t savecrit; + register_t eflags; cy_addr iobase; basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1)); car = com->unit & CD1400_CAR_CHAN; cy_align = com->cy_align; iobase = com->iobase; - intrsave = save_intr(); - disable_intr(); - if (intrsave & PSL_I) + eflags = read_eflags(); + savecrit = critical_enter(); + if (eflags & PSL_I) COM_LOCK(); if (basecom->car != car) cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car); cd_outb(iobase, reg, cy_align, val); - if (intrsave & PSL_I) + if (eflags & PSL_I) COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } #ifdef CyDebug diff --git a/sys/dev/sound/isa/mpu.c b/sys/dev/sound/isa/mpu.c index 765301088192..d4175133647b 100644 --- a/sys/dev/sound/isa/mpu.c +++ b/sys/dev/sound/isa/mpu.c @@ -241,6 +241,7 @@ mpu_probe2(device_t dev) sc_p scp; int unit, i; intrmask_t irqp0, irqp1; + critical_t savecrit; scp = device_get_softc(dev); unit = device_get_unit(dev); @@ -266,7 +267,7 @@ mpu_probe2(device_t dev) * Idea-stolen-from: sys/isa/sio.c:sioprobe() */ - disable_intr(); + savecrit = critical_enter(); /* * See the initial irq. We have to do this now, @@ -278,7 +279,7 @@ mpu_probe2(device_t dev) /* Switch to uart mode. */ if (mpu_uartmode(scp) != 0) { - enable_intr(); + critical_exit(savecrit); printf("mpu%d: mode switching failed.\n", unit); mpu_releaseres(scp, dev); return (ENXIO); @@ -297,7 +298,7 @@ mpu_probe2(device_t dev) break; } if (irqp1 == irqp0) { - enable_intr(); + critical_exit(savecrit); printf("mpu%d: switching the mode gave no interrupt.\n", unit); mpu_releaseres(scp, dev); return (ENXIO); @@ -306,13 +307,13 @@ mpu_probe2(device_t dev) no_irq: /* Wait to see an ACK. */ if (mpu_waitack(scp) != 0) { - enable_intr(); + critical_exit(savecrit); printf("mpu%d: not acked.\n", unit); mpu_releaseres(scp, dev); return (ENXIO); } - enable_intr(); + critical_exit(savecrit); if (device_get_flags(dev) & MPU_DF_NO_IRQ) scp->irq_val = 0; diff --git a/sys/i386/i386/db_interface.c b/sys/i386/i386/db_interface.c index ee4ab194d173..ea2b8625cc74 100644 --- a/sys/i386/i386/db_interface.c +++ b/sys/i386/i386/db_interface.c @@ -309,7 +309,8 @@ Debugger(msg) const char *msg; { static volatile u_int in_Debugger; - int flags; + critical_t savecrit; + /* * XXX * Do nothing if the console is in graphics mode. This is @@ -319,12 +320,11 @@ Debugger(msg) if (cons_unavail && !(boothowto & RB_GDB)) return; - if (atomic_cmpset_int(&in_Debugger, 0, 1)) { - flags = save_intr(); - disable_intr(); + if (atomic_cmpset_acq_int(&in_Debugger, 0, 1)) { + savecrit = critical_enter(); db_printf("Debugger(\"%s\")\n", msg); breakpoint(); - restore_intr(flags); - in_Debugger = 0; + critical_exit(savecrit); + atomic_store_rel_int(&in_Debugger, 0); } } diff --git a/sys/i386/i386/initcpu.c b/sys/i386/i386/initcpu.c index b42c234d36da..8b39b447a7a8 100644 --- a/sys/i386/i386/initcpu.c +++ b/sys/i386/i386/initcpu.c @@ -607,15 +607,14 @@ void enable_K5_wt_alloc(void) { u_int64_t msr; - int intrstate; + critical_t savecrit; /* * Write allocate is supported only on models 1, 2, and 3, with * a stepping of 4 or greater. */ if (((cpu_id & 0xf0) > 0) && ((cpu_id & 0x0f) > 3)) { - intrstate = save_intr(); - disable_intr(); + savecrit = critical_enter(); msr = rdmsr(0x83); /* HWCR */ wrmsr(0x83, msr & !(0x10)); @@ -647,7 +646,7 @@ enable_K5_wt_alloc(void) msr=rdmsr(0x83); wrmsr(0x83, msr|0x10); /* enable write allocate */ - restore_intr(intrstate); + critical_exit(savecrit); } } diff --git a/sys/i386/i386/perfmon.c b/sys/i386/i386/perfmon.c index 435cc2ff9e32..2d383129247e 100644 --- a/sys/i386/i386/perfmon.c +++ b/sys/i386/i386/perfmon.c @@ -117,19 +117,18 @@ perfmon_avail(void) int perfmon_setup(int pmc, unsigned int control) { - int intrstate; + critical_t savecrit; if (pmc < 0 || pmc >= NPMC) return EINVAL; perfmon_inuse |= (1 << pmc); control &= ~(PMCF_SYS_FLAGS << 16); - intrstate = save_intr(); - disable_intr(); + savecrit = critical_enter(); ctl_shadow[pmc] = control; writectl(pmc); wrmsr(msr_pmc[pmc], pmc_shadow[pmc] = 0); - restore_intr(intrstate); + critical_exit(savecrit); return 0; } @@ -164,18 +163,17 @@ perfmon_fini(int pmc) int perfmon_start(int pmc) { - int intrstate; + critical_t savecrit; if (pmc < 0 || pmc >= NPMC) return EINVAL; if (perfmon_inuse & (1 << pmc)) { - intrstate = save_intr(); - disable_intr(); + savecrit = critical_enter(); ctl_shadow[pmc] |= (PMCF_EN << 16); wrmsr(msr_pmc[pmc], pmc_shadow[pmc]); writectl(pmc); - restore_intr(intrstate); + critical_exit(savecrit); return 0; } return EBUSY; @@ -184,18 +182,17 @@ perfmon_start(int pmc) int perfmon_stop(int pmc) { - int intrstate; + critical_t savecrit; if (pmc < 0 || pmc >= NPMC) return EINVAL; if (perfmon_inuse & (1 << pmc)) { - intrstate = save_intr(); - disable_intr(); + savecrit = critical_enter(); pmc_shadow[pmc] = rdmsr(msr_pmc[pmc]) & 0xffffffffffULL; ctl_shadow[pmc] &= ~(PMCF_EN << 16); writectl(pmc); - restore_intr(intrstate); + critical_exit(savecrit); return 0; } return EBUSY; diff --git a/sys/i386/isa/cy.c b/sys/i386/isa/cy.c index f5161a6f4eb3..6f4aaf654c9f 100644 --- a/sys/i386/isa/cy.c +++ b/sys/i386/isa/cy.c @@ -350,7 +350,7 @@ static int cd_getreg __P((struct com_s *com, int reg)); static void cd_setreg __P((struct com_s *com, int reg, int val)); static timeout_t siodtrwakeup; static void comhardclose __P((struct com_s *com)); -static void sioinput __P((struct com_s *com)); +static void sioinput __P((struct com_s *com, critical_t *savecrit)); #if 0 static void siointr1 __P((struct com_s *com)); #endif @@ -672,7 +672,7 @@ sioopen(dev, flag, mode, p) int s; struct tty *tp; int unit; - int intrsave; + critical_t savecrit; mynor = minor(dev); unit = MINOR_TO_UNIT(mynor); @@ -779,8 +779,7 @@ open_top: } } - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); (void) inb(com->line_status_port); (void) inb(com->data_port); @@ -789,7 +788,7 @@ open_top: outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY | IER_ERLS | IER_EMSC); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); #else /* !0 */ /* * Flush fifos. This requires a full channel reset which @@ -800,8 +799,7 @@ open_top: CD1400_CCR_CMDRESET | CD1400_CCR_CHANRESET); cd1400_channel_cmd(com, com->channel_control); - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com->prev_modem_status = com->last_modem_status = cd_getreg(com, CD1400_MSVR2); @@ -809,7 +807,7 @@ open_top: com->intr_enable = CD1400_SRER_MDMCH | CD1400_SRER_RXDATA); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); #endif /* 0 */ /* * Handle initial DCD. Callout devices get a fake initial @@ -892,7 +890,7 @@ comhardclose(com) int s; struct tty *tp; int unit; - int intrsave; + critical_t savecrit; unit = com->unit; iobase = com->iobase; @@ -906,13 +904,12 @@ comhardclose(com) outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK); #else /* XXX */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com->etc = ETC_NONE; cd_setreg(com, CD1400_COR2, com->cor[1] &= ~CD1400_COR2_ETC); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF); #endif @@ -920,12 +917,11 @@ comhardclose(com) #if 0 outb(iobase + com_ier, 0); #else - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); cd_setreg(com, CD1400_SRER, com->intr_enable = 0); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); #endif tp = com->tp; if ((tp->t_cflag & HUPCL) @@ -1021,15 +1017,15 @@ siodtrwakeup(chan) * b) needs to return with COM_LOCK() held. */ static void -sioinput(com) +sioinput(com, savecrit) struct com_s *com; + critical_t *savecrit; { u_char *buf; int incc; u_char line_status; int recv_data; struct tty *tp; - int intrsave; buf = com->ibuf; tp = com->tp; @@ -1053,9 +1049,8 @@ sioinput(com) * semantics instead of the save-and-disable semantics * that are used everywhere else. */ - intrsave = save_intr(); COM_UNLOCK(); - enable_intr(); + critical_exit(*savecrit); incc = com->iptr - buf; if (tp->t_rawq.c_cc + incc > tp->t_ihiwat && (com->state & CS_RTS_IFLOW @@ -1076,7 +1071,7 @@ sioinput(com) tp->t_lflag &= ~FLUSHO; comstart(tp); } - restore_intr(intrsave); + *savecrit = critical_enter(); COM_LOCK(); } while (buf < com->iptr); } else { @@ -1086,9 +1081,8 @@ sioinput(com) * semantics instead of the save-and-disable semantics * that are used everywhere else. */ - intrsave = save_intr(); COM_UNLOCK(); - enable_intr(); + critical_exit(*savecrit); line_status = buf[com->ierroff]; recv_data = *buf++; if (line_status @@ -1103,7 +1097,7 @@ sioinput(com) recv_data |= TTY_PE; } (*linesw[tp->t_line].l_rint)(recv_data, tp); - restore_intr(intrsave); + *savecrit = critical_enter(); COM_LOCK(); } while (buf < com->iptr); } @@ -1777,7 +1771,7 @@ static void siopoll(void *arg) { int unit; - int intrsave; + critical_t savecrit; #ifdef CyDebug ++cy_timeouts; @@ -1800,8 +1794,7 @@ repeat: * (actually never opened devices) so that we don't * loop. */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); incc = com->iptr - com->ibuf; com->iptr = com->ibuf; @@ -1811,7 +1804,7 @@ repeat: } com_events -= incc; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (incc != 0) log(LOG_DEBUG, "sio%d: %d events for device with no tp\n", @@ -1819,39 +1812,36 @@ repeat: continue; } if (com->iptr != com->ibuf) { - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); - sioinput(com); + sioinput(com, &savecrit); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } if (com->state & CS_CHECKMSR) { u_char delta_modem_status; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); - sioinput(com); + sioinput(com, &savecrit); delta_modem_status = com->last_modem_status ^ com->prev_modem_status; com->prev_modem_status = com->last_modem_status; com_events -= LOTS_OF_EVENTS; com->state &= ~CS_CHECKMSR; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (delta_modem_status & MSR_DCD) (*linesw[tp->t_line].l_modem) (tp, com->prev_modem_status & MSR_DCD); } if (com->extra_state & CSE_ODONE) { - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com_events -= LOTS_OF_EVENTS; com->extra_state &= ~CSE_ODONE; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (!(com->state & CS_BUSY)) { tp->t_state &= ~TS_BUSY; ttwwakeup(com->tp); @@ -1863,13 +1853,12 @@ repeat: } } if (com->state & CS_ODONE) { - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com_events -= LOTS_OF_EVENTS; com->state &= ~CS_ODONE; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); (*linesw[tp->t_line].l_start)(tp); } if (com_events == 0) @@ -1898,7 +1887,7 @@ comparam(tp, t) u_char opt; int s; int unit; - int intrsave; + critical_t savecrit; /* do historical conversions */ if (t->c_ispeed == 0) @@ -2046,15 +2035,14 @@ comparam(tp, t) if (cflag & CCTS_OFLOW) opt |= CD1400_COR2_CCTS_OFLOW; #endif - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (opt != com->cor[1]) { cor_change |= CD1400_CCR_COR2; cd_setreg(com, CD1400_COR2, com->cor[1] = opt); } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); /* * set channel option register 3 - @@ -2175,8 +2163,7 @@ comparam(tp, t) * XXX should have done this long ago, but there is too much state * to change all atomically. */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); com->state &= ~CS_TTGO; @@ -2244,7 +2231,7 @@ comparam(tp, t) } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); splx(s); comstart(tp); if (com->ibufold != NULL) { @@ -2263,7 +2250,7 @@ siosetwater(com, speed) u_char *ibuf; int ibufsize; struct tty *tp; - int intrsave; + critical_t savecrit; /* * Make the buffer size large enough to handle a softtty interrupt @@ -2301,11 +2288,10 @@ siosetwater(com, speed) * Read current input buffer, if any. Continue with interrupts * disabled. */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->iptr != com->ibuf) - sioinput(com); + sioinput(com, &savecrit); /*- * Initialize critical variables, including input buffer watermarks. @@ -2324,7 +2310,7 @@ siosetwater(com, speed) com->ihighwater = ibuf + 3 * ibufsize / 4; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); return (0); } @@ -2338,7 +2324,7 @@ comstart(tp) bool_t started; #endif int unit; - int intrsave; + critical_t savecrit; unit = DEV_TO_UNIT(tp->t_dev); com = com_addr(unit); @@ -2349,8 +2335,7 @@ comstart(tp) started = FALSE; #endif - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (tp->t_state & TS_TTSTOP) { com->state &= ~CS_TTGO; @@ -2388,7 +2373,7 @@ comstart(tp) #endif } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) { ttwwakeup(tp); splx(s); @@ -2407,8 +2392,7 @@ comstart(tp) sizeof com->obuf1); com->obufs[0].l_next = NULL; com->obufs[0].l_queued = TRUE; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->state & CS_BUSY) { qp = com->obufq.l_next; @@ -2429,7 +2413,7 @@ comstart(tp) | CD1400_SRER_TXRDY); } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) { #ifdef CyDebug @@ -2440,8 +2424,7 @@ comstart(tp) sizeof com->obuf2); com->obufs[1].l_next = NULL; com->obufs[1].l_queued = TRUE; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->state & CS_BUSY) { qp = com->obufq.l_next; @@ -2462,7 +2445,7 @@ comstart(tp) | CD1400_SRER_TXRDY); } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } tp->t_state |= TS_BUSY; } @@ -2471,13 +2454,12 @@ comstart(tp) ++com->start_real; #endif #if 0 - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->state >= (CS_BUSY | CS_TTGO)) siointr1(com); /* fake interrupt to start output */ COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); #endif ttwwakeup(tp); splx(s); @@ -2490,12 +2472,11 @@ comstop(tp, rw) { struct com_s *com; bool_t wakeup_etc; - int intrsave; + critical_t savecrit; com = com_addr(DEV_TO_UNIT(tp->t_dev)); wakeup_etc = FALSE; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (rw & FWRITE) { com->obufs[0].l_queued = FALSE; @@ -2520,7 +2501,7 @@ comstop(tp, rw) com->iptr = com->ibuf; } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (wakeup_etc) wakeup(&com->etc); if (rw & FWRITE && com->etc == ETC_NONE) @@ -2536,7 +2517,7 @@ commctl(com, bits, how) { int mcr; int msr; - int intrsave; + critical_t savecrit; if (how == DMGET) { if (com->channel_control & CD1400_CCR_RCVEN) @@ -2574,8 +2555,7 @@ commctl(com, bits, how) mcr |= com->mcr_dtr; if (bits & TIOCM_RTS) mcr |= com->mcr_rts; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); switch (how) { case DMSET: @@ -2595,7 +2575,7 @@ commctl(com, bits, how) break; } COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); return (0); } @@ -2657,14 +2637,13 @@ comwakeup(chan) com = com_addr(unit); if (com != NULL && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) { - int intrsave; + critical_t savecrit; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); siointr1(com); COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } } #endif @@ -2684,15 +2663,14 @@ comwakeup(chan) for (errnum = 0; errnum < CE_NTYPES; ++errnum) { u_int delta; u_long total; - int intrsave; + critical_t savecrit; - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); delta = com->delta_error_counts[errnum]; com->delta_error_counts[errnum] = 0; COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); if (delta == 0) continue; total = com->error_counts[errnum] += delta; @@ -2844,7 +2822,7 @@ cd_etc(com, etc) struct com_s *com; int etc; { - int intrsave; + critical_t savecrit; /* * We can't change the hardware's ETC state while there are any @@ -2857,8 +2835,7 @@ cd_etc(com, etc) * for the tx to become empty so that the command is sure to be * executed soon after we issue it. */ - intrsave = save_intr(); - disable_intr(); + savecrit = critical_enter(); COM_LOCK(); if (com->etc == etc) goto wait; @@ -2869,7 +2846,7 @@ cd_etc(com, etc) && (com->etc == ETC_BREAK_ENDING || com->etc == ETC_BREAK_ENDED || com->etc == ETC_NONE))) { COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); return; } com->etc = etc; @@ -2878,7 +2855,7 @@ cd_etc(com, etc) = (com->intr_enable & ~CD1400_SRER_TXRDY) | CD1400_SRER_TXMPTY); wait: COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); while (com->etc == etc && tsleep(&com->etc, TTIPRI | PCATCH, "cyetc", 0) == 0) continue; @@ -2892,7 +2869,8 @@ cd_getreg(com, reg) struct com_s *basecom; u_char car; int cy_align; - int intrsave; + criticale_t savecrit; + register_t eflags; cy_addr iobase; int val; @@ -2900,16 +2878,16 @@ cd_getreg(com, reg) car = com->unit & CD1400_CAR_CHAN; cy_align = com->cy_align; iobase = com->iobase; - intrsave = save_intr(); - disable_intr(); - if (intrsave & PSL_I) + eflags = read_eflags(); + savecrit = critical_enter(); + if (eflags & PSL_I) COM_LOCK(); if (basecom->car != car) cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car); val = cd_inb(iobase, reg, cy_align); - if (intrsave & PSL_I) + if (eflags & PSL_I) COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); return (val); } @@ -2922,23 +2900,24 @@ cd_setreg(com, reg, val) struct com_s *basecom; u_char car; int cy_align; - int intrsave; + critical_t savecrit; + register_t eflags; cy_addr iobase; basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1)); car = com->unit & CD1400_CAR_CHAN; cy_align = com->cy_align; iobase = com->iobase; - intrsave = save_intr(); - disable_intr(); - if (intrsave & PSL_I) + eflags = read_eflags(); + savecrit = critical_enter(); + if (eflags & PSL_I) COM_LOCK(); if (basecom->car != car) cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car); cd_outb(iobase, reg, cy_align, val); - if (intrsave & PSL_I) + if (eflags & PSL_I) COM_UNLOCK(); - restore_intr(intrsave); + critical_exit(savecrit); } #ifdef CyDebug diff --git a/sys/i386/isa/npx.c b/sys/i386/isa/npx.c index 285612355cf6..56e23a02d6d2 100644 --- a/sys/i386/isa/npx.c +++ b/sys/i386/isa/npx.c @@ -220,7 +220,7 @@ npx_probe(dev) #else /* SMP */ int result; - u_long save_eflags; + critical_t savecrit; u_char save_icu1_mask; u_char save_icu2_mask; struct gate_descriptor save_idt_npxintr; @@ -235,8 +235,7 @@ npx_probe(dev) if (resource_int_value("npx", 0, "irq", &npx_irq) != 0) npx_irq = 13; npx_intrno = NRSVIDT + npx_irq; - save_eflags = read_eflags(); - disable_intr(); + savecrit = critical_enter(); save_icu1_mask = inb(IO_ICU1 + 1); save_icu2_mask = inb(IO_ICU2 + 1); save_idt_npxintr = idt[npx_intrno]; @@ -252,14 +251,14 @@ npx_probe(dev) * needs interrupts enabled. Does this make any difference * here? */ - enable_intr(); + critical_exit(savecrit); result = npx_probe1(dev); - disable_intr(); + savecrit = critical_enter(); outb(IO_ICU1 + 1, save_icu1_mask); outb(IO_ICU2 + 1, save_icu2_mask); idt[npx_intrno] = save_idt_npxintr; idt[16] = save_idt_npxtrap; - write_eflags(save_eflags); + critical_exit(savecrit); return (result); #endif /* SMP */ @@ -798,7 +797,7 @@ npx_intr(dummy) int npxdna() { - int s; + critical_t s; if (!npx_exists) return (0); @@ -807,8 +806,7 @@ npxdna() PCPU_GET(npxproc), curproc); panic("npxdna"); } - s = save_intr(); - disable_intr(); + s = critical_enter(); stop_emulating(); /* * Record new context early in case frstor causes an IRQ13. @@ -828,7 +826,7 @@ npxdna() * first FPU instruction after a context switch. */ frstor(&PCPU_GET(curpcb)->pcb_savefpu); - restore_intr(s); + critical_exit(s); return (1); } @@ -855,28 +853,27 @@ npxsave(addr) #else /* SMP */ - int intrstate; + critical_t savecrit; u_char icu1_mask; u_char icu2_mask; u_char old_icu1_mask; u_char old_icu2_mask; struct gate_descriptor save_idt_npxintr; - intrstate = save_intr(); - disable_intr(); + savecrit = critical_enter(); old_icu1_mask = inb(IO_ICU1 + 1); old_icu2_mask = inb(IO_ICU2 + 1); save_idt_npxintr = idt[npx_intrno]; outb(IO_ICU1 + 1, old_icu1_mask & ~(IRQ_SLAVE | npx0_imask)); outb(IO_ICU2 + 1, old_icu2_mask & ~(npx0_imask >> 8)); idt[npx_intrno] = npx_idt_probeintr; - write_eflags(intrstate); + critical_exit(savecrit); stop_emulating(); fnsave(addr); fnop(); start_emulating(); + savecrit = critical_enter(); PCPU_SET(npxproc, NULL); - disable_intr(); icu1_mask = inb(IO_ICU1 + 1); /* masks may have changed */ icu2_mask = inb(IO_ICU2 + 1); outb(IO_ICU1 + 1, @@ -885,7 +882,7 @@ npxsave(addr) (icu2_mask & ~(npx0_imask >> 8)) | (old_icu2_mask & (npx0_imask >> 8))); idt[npx_intrno] = save_idt_npxintr; - restore_intr(intrstate); /* back to previous state */ + critical_exit(savecrit); /* back to previous state */ #endif /* SMP */ } diff --git a/sys/ia64/ia64/pmap.c b/sys/ia64/ia64/pmap.c index 0c396c0eba51..3743354f9168 100644 --- a/sys/ia64/ia64/pmap.c +++ b/sys/ia64/ia64/pmap.c @@ -409,13 +409,12 @@ pmap_invalidate_all(pmap_t pmap) { u_int64_t addr; int i, j; - u_int32_t psr; + critical_t psr; KASSERT(pmap == PCPU_GET(current_pmap), ("invalidating TLB for non-current pmap")); - psr = save_intr(); - disable_intr(); + psr = critical_enter(); addr = pmap_pte_e_base; for (i = 0; i < pmap_pte_e_count1; i++) { for (j = 0; j < pmap_pte_e_count2; j++) { @@ -424,7 +423,7 @@ pmap_invalidate_all(pmap_t pmap) } addr += pmap_pte_e_stride1; } - restore_intr(psr); + critical_exit(psr); } static void diff --git a/sys/kern/kern_ktr.c b/sys/kern/kern_ktr.c index 3f00c8d03411..1422a3e1ba79 100644 --- a/sys/kern/kern_ktr.c +++ b/sys/kern/kern_ktr.c @@ -117,7 +117,8 @@ ktr_tracepoint(u_int mask, const char *format, u_long arg1, u_long arg2, #endif { struct ktr_entry *entry; - int newindex, saveindex, saveintr; + int newindex, saveindex; + critical_t savecrit; #ifdef KTR_EXTEND va_list ap; #endif @@ -130,14 +131,13 @@ ktr_tracepoint(u_int mask, const char *format, u_long arg1, u_long arg2, if (((1 << KTR_CPU) & ktr_cpumask) == 0) return; #endif - saveintr = save_intr(); - disable_intr(); + savecrit = critical_enter(); do { saveindex = ktr_idx; newindex = (saveindex + 1) & (KTR_ENTRIES - 1); } while (atomic_cmpset_rel_int(&ktr_idx, saveindex, newindex) == 0); entry = &ktr_buf[saveindex]; - restore_intr(saveintr); + critical_exit(savecrit); if (ktr_mask & KTR_LOCK) /* * We can't use nanotime with KTR_LOCK, it would cause diff --git a/sys/kern/subr_prof.c b/sys/kern/subr_prof.c index 5277a586c3b2..ce71fb6f132d 100644 --- a/sys/kern/subr_prof.c +++ b/sys/kern/subr_prof.c @@ -92,7 +92,7 @@ kmstartup(dummy) int nullfunc_loop_overhead; int nullfunc_loop_profiled_time; uintfptr_t tmp_addr; - int intrstate; + critical_t savecrit; #endif /* @@ -135,8 +135,7 @@ kmstartup(dummy) * Disable interrupts to avoid interference while we calibrate * things. */ - intrstate = save_intr(); - disable_intr(); + savecrit = critical_enter(); /* * Determine overheads. @@ -190,7 +189,7 @@ kmstartup(dummy) p->state = GMON_PROF_OFF; stopguprof(p); - restore_intr(intrstate); + critical_exit(savecrit); nullfunc_loop_profiled_time = 0; for (tmp_addr = (uintfptr_t)nullfunc_loop_profiled; diff --git a/sys/pc98/pc98/npx.c b/sys/pc98/pc98/npx.c index c656736d7893..b04e0089bf78 100644 --- a/sys/pc98/pc98/npx.c +++ b/sys/pc98/pc98/npx.c @@ -239,7 +239,7 @@ npx_probe(dev) #else /* SMP */ int result; - u_long save_eflags; + critical_t savecrit; u_char save_icu1_mask; u_char save_icu2_mask; struct gate_descriptor save_idt_npxintr; @@ -258,8 +258,7 @@ npx_probe(dev) npx_irq = 13; #endif npx_intrno = NRSVIDT + npx_irq; - save_eflags = read_eflags(); - disable_intr(); + savecrit = critcal_enter(); #ifdef PC98 save_icu1_mask = inb(IO_ICU1 + 2); save_icu2_mask = inb(IO_ICU2 + 2); @@ -285,9 +284,9 @@ npx_probe(dev) * needs interrupts enabled. Does this make any difference * here? */ - enable_intr(); + critical_exit(savecrit); result = npx_probe1(dev); - disable_intr(); + savecrit = critcal_enter(); #ifdef PC98 outb(IO_ICU1 + 2, save_icu1_mask); outb(IO_ICU2 + 2, save_icu2_mask); @@ -297,7 +296,7 @@ npx_probe(dev) #endif idt[npx_intrno] = save_idt_npxintr; idt[16] = save_idt_npxtrap; - write_eflags(save_eflags); + critical_exit(savecrit); return (result); #endif /* SMP */ @@ -852,7 +851,7 @@ npx_intr(dummy) int npxdna() { - int s; + critical_t s; if (!npx_exists) return (0); @@ -861,8 +860,7 @@ npxdna() PCPU_GET(npxproc), curproc); panic("npxdna"); } - s = save_intr(); - disable_intr(); + s = critical_enter(); stop_emulating(); /* * Record new context early in case frstor causes an IRQ13. @@ -882,7 +880,7 @@ npxdna() * first FPU instruction after a context switch. */ frstor(&PCPU_GET(curpcb)->pcb_savefpu); - restore_intr(s); + critical_exit(s); return (1); } @@ -909,15 +907,14 @@ npxsave(addr) #else /* SMP */ - int intrstate; + critical_t savecrit; u_char icu1_mask; u_char icu2_mask; u_char old_icu1_mask; u_char old_icu2_mask; struct gate_descriptor save_idt_npxintr; - intrstate = save_intr(); - disable_intr(); + savecrit = critcal_enter(); #ifdef PC98 old_icu1_mask = inb(IO_ICU1 + 2); old_icu2_mask = inb(IO_ICU2 + 2); @@ -934,13 +931,13 @@ npxsave(addr) outb(IO_ICU2 + 1, old_icu2_mask & ~(npx0_imask >> 8)); #endif idt[npx_intrno] = npx_idt_probeintr; - write_eflags(intrstate); + critical_exit(savecrit); stop_emulating(); fnsave(addr); fnop(); start_emulating(); PCPU_SET(npxproc, NULL); - disable_intr(); + savecrit = critcal_enter(); #ifdef PC98 icu1_mask = inb(IO_ICU1 + 2); /* masks may have changed */ icu2_mask = inb(IO_ICU2 + 2); @@ -959,7 +956,7 @@ npxsave(addr) | (old_icu2_mask & (npx0_imask >> 8))); #endif idt[npx_intrno] = save_idt_npxintr; - restore_intr(intrstate); /* back to previous state */ + critical_exit(savecrit); /* back to previous state */ #endif /* SMP */ } |