From 9925a66491591c24c4a463d6d367aae15b0c2e7d Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 26 Jun 2002 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2002-06-26 --- bitsy/devether.c | 2 +- bitsy/devpcmcia.c | 109 ++++++++++++++++++++++++---------------------- bitsy/power.c | 2 +- pc/ether8139.c | 2 +- pc/wavelan.c | 32 +++++++++----- port/portdat.h | 1 + port/proc.c | 4 +- port/taslock.c | 4 +- 8 files changed, 86 insertions(+), 70 deletions(-) diff --git a/bitsy/devether.c b/bitsy/devether.c index 82ca462c9d89a78aa2de8a0afd4083648591e616..f0b904d94be943b4f313e83355f833af9b8d9613 100644 --- a/bitsy/devether.c +++ b/bitsy/devether.c @@ -36,7 +36,7 @@ etherpower(int on) Ether *ether; /* Power all ether cards on or off */ -print("etherpower %d\n", on); +iprint("etherpower %d\n", on); for (i = 0; i < MaxEther; i++){ if ((ether = etherxx[i]) == nil) continue; diff --git a/bitsy/devpcmcia.c b/bitsy/devpcmcia.c index 50e46db3bb208b8e5c22ce543e0f5cfa1a718806..4b55326f2840aa31ebd9af82b808a6c905702eb2 100644 --- a/bitsy/devpcmcia.c +++ b/bitsy/devpcmcia.c @@ -105,57 +105,6 @@ bitno(ulong x) return i; } -/* - * power up/down pcmcia - */ -void -pcmciapower(int on) -{ - PCMslot *sp; - - /* if there's no pcmcia sleave, no interrupts */ - if(gpioregs->level & GPIO_OPT_IND_i) - return; - if (on){ - /* set timing to the default, 300 */ - slottiming(0, 300, 300, 300, 0); - slottiming(1, 300, 300, 300, 0); - - /* if there's no pcmcia sleave, no interrupts */ - if(gpioregs->level & GPIO_OPT_IND_i) - return; - - egpiobits(EGPIO_exp_nvram_power|EGPIO_exp_full_power, 1); - delay(200); - egpiobits(EGPIO_pcmcia_reset, 1); - delay(100); - egpiobits(EGPIO_pcmcia_reset, 0); - delay(500); - - slotinfo(nil, nil); // See what's there - for (sp = slot; sp < slot + nslot; sp++){ - if (sp->occupied == 0) - continue; - if(sp->cisread == 0) - pcmcisread(sp); - if (sp->dev){ -// if (sp->dev->power) -// sp->dev->power(on); - } - } - }else{ - for (sp = slot; sp < slot + nslot; sp++){ - if (sp->occupied == 0) - continue; - if (sp->dev){ - if (sp->dev->power) - sp->dev->power(on); - } - } - egpiobits(EGPIO_exp_nvram_power|EGPIO_exp_full_power, 0); - } -} - /* * set up the cards, default timing is 300 ns */ @@ -448,6 +397,55 @@ pcmciawrite(Chan *c, void *a, long n, vlong off) return -1; /* not reached */ } +/* + * power up/down pcmcia + */ +void +pcmciapower(int on) +{ + PCMslot *sp; + + /* if there's no pcmcia sleave, no interrupts */ +iprint("pcmciapower %d\n", on); + + if (on){ + /* set timing to the default, 300 */ + slottiming(0, 300, 300, 300, 0); + slottiming(1, 300, 300, 300, 0); + + /* if there's no pcmcia sleave, no interrupts */ + if(gpioregs->level & GPIO_OPT_IND_i){ + iprint("pcmciapower: no sleeve\n"); + return; + } + + for (sp = slot; sp < slot + nslot; sp++){ + if (sp->dev){ + increfp(sp); + iprint("pcmciapower: %s\n", sp->verstr); + if (sp->dev->power) + sp->dev->power(on); + } + } + }else{ + if(gpioregs->level & GPIO_OPT_IND_i){ + iprint("pcmciapower: no sleeve\n"); + return; + } + + for (sp = slot; sp < slot + nslot; sp++){ + if (sp->dev){ + if (sp->dev->power) + sp->dev->power(on); + decrefp(sp); + } + sp->occupied = 0; + sp->cisread = 0; + } + egpiobits(EGPIO_exp_nvram_power|EGPIO_exp_full_power, 0); + } +} + Dev pcmciadevtab = { 'y', "pcmcia", @@ -510,7 +508,9 @@ increfp(PCMslot *sp) nexterror(); } +iprint("increfp %ld\n", sp - slot); if(incref(&pcmcia) == 1){ +iprint("increfp full power\n"); egpiobits(EGPIO_exp_nvram_power|EGPIO_exp_full_power, 1); delay(200); egpiobits(EGPIO_pcmcia_reset, 1); @@ -531,13 +531,16 @@ increfp(PCMslot *sp) static void decrefp(PCMslot *sp) { +iprint("decrefp %ld\n", sp - slot); decref(&sp->ref); - if(decref(&pcmcia) == 0) + if(decref(&pcmcia) == 0){ +iprint("increfp power down\n"); egpiobits(EGPIO_exp_nvram_power|EGPIO_exp_full_power, 0); + } } /* - * the regions are staticly masped + * the regions are staticly mapped */ static void slotmap(int slotno, ulong regs, ulong attr, ulong mem) diff --git a/bitsy/power.c b/bitsy/power.c index 19995ae4f0f5f6d1ce937e7a8441e73e980c8edc..69d4114f864354547e244e4a6e4bde7b0e74724b 100644 --- a/bitsy/power.c +++ b/bitsy/power.c @@ -212,7 +212,7 @@ deepsleep(void) { audiopower(1); µcpower(1); screenpower(1); - // pcmciapower(1); + pcmciapower(1); splx(power_pl); return; } diff --git a/pc/ether8139.c b/pc/ether8139.c index f83efd94e98bfd47cf4eba786a3de30ee3c54562..e7cac72940eb70f3d0751c09906addc1a348d7fd 100644 --- a/pc/ether8139.c +++ b/pc/ether8139.c @@ -73,7 +73,7 @@ enum { /* Imr/Isr */ PunLc = 0x0020, /* Packet Underrun or Link Change */ Fovw = 0x0040, /* Receive FIFO Overflow */ Clc = 0x2000, /* Cable Length Change */ - Timerbit = 0x4000, /* Timer */ + Timerbit = 0x4000, /* Timer */ Serr = 0x8000, /* System Error */ }; diff --git a/pc/wavelan.c b/pc/wavelan.c index 8faae4e3e0c2c3d16d89c5c6ef580c367eee55da..45fe1b339a448e79eed1aeaa7d23391dc1b13df6 100644 --- a/pc/wavelan.c +++ b/pc/wavelan.c @@ -471,7 +471,7 @@ w_txstart(Ether* ether) Block *bp; int len, off; - if((ctlr = ether->ctlr) == nil || (ctlr->state & (Attached|Power)) == 0 || ctlr->txbusy) + if((ctlr = ether->ctlr) == nil || (ctlr->state & (Attached|Power)) != (Attached|Power) || ctlr->txbusy) return; if((bp = qget(ether->oq)) == nil) @@ -618,7 +618,7 @@ w_timer(void* arg) ctlr = (Ctlr*)ether->ctlr; if(ctlr == 0) break; - if((ctlr->state & Attached) == 0) + if((ctlr->state & (Attached|Power)) != (Attached|Power)) continue; ctlr->ticks++; @@ -698,7 +698,7 @@ w_detach(Ether* ether) Ctlr* ctlr; char name[64]; - if(ether->ctlr == 0) + if(ether->ctlr == nil) return; snprint(name, sizeof(name), "#l%dtimer", ether->ctlrno); @@ -714,6 +714,7 @@ w_detach(Ether* ether) ctlr->state &= ~Attached; iunlock(ctlr); } + ether->ctlr = nil; } void @@ -723,8 +724,16 @@ w_power(Ether* ether, int on) ctlr = (Ctlr*) ether->ctlr; ilock(ctlr); +iprint("w_power %d\n", on); if(on){ if((ctlr->state & Power) == 0){ + if (wavelanreset(ether, ctlr) < 0){ + iprint("w_power: reset failed\n"); + iunlock(ctlr); + w_detach(ether); + free(ctlr); + return; + } if(ctlr->state & Attached) w_enable(ether); ctlr->state |= Power; @@ -1055,9 +1064,10 @@ wavelanreset(Ether* ether, Ctlr *ctlr) { Wltv ltv; + iprint("wavelanreset, iob 0x%ux\n", ctlr->iob); w_intdis(ctlr); if(w_cmd(ctlr,WCmdIni,0)){ - print("#l%d: init failed\n", ether->ctlrno); + iprint("#l%d: init failed\n", ether->ctlrno); return -1; } w_intdis(ctlr); @@ -1081,7 +1091,7 @@ wavelanreset(Ether* ether, Ctlr *ctlr) ltv.type = WTyp_Mac; ltv.len = 4; if(w_inltv(ctlr, <v)){ - print("#l%d: unable to read mac addr\n", + iprint("#l%d: unable to read mac addr\n", ether->ctlrno); return -1; } @@ -1100,7 +1110,7 @@ wavelanreset(Ether* ether, Ctlr *ctlr) ctlr->state |= Power; // free old Ctlr struct if resetting after suspend - if(ether->ctlr) + if(ether->ctlr && ether->ctlr != ctlr) free(ether->ctlr); // link to ether @@ -1117,11 +1127,11 @@ wavelanreset(Ether* ether, Ctlr *ctlr) ether->multicast = w_multicast; ether->arg = ether; -// DEBUG("#l%d: irq %ld port %lx type %s", -// ether->ctlrno, ether->irq, ether->port, ether->type); -// DEBUG(" %2.2uX%2.2uX%2.2uX%2.2uX%2.2uX%2.2uX\n", -// ether->ea[0], ether->ea[1], ether->ea[2], -// ether->ea[3], ether->ea[4], ether->ea[5]); + DEBUG("#l%d: intnum %ld port %lx type %s", + ether->ctlrno, ether->intnum, ether->port, ether->type); + DEBUG(" %2.2uX%2.2uX%2.2uX%2.2uX%2.2uX%2.2uX\n", + ether->ea[0], ether->ea[1], ether->ea[2], + ether->ea[3], ether->ea[4], ether->ea[5]); return 0; } diff --git a/port/portdat.h b/port/portdat.h index 120be85b83f22ec5e70d0985e2b738650aeded51..619cf34f7feca8d4e958463308038a0d4622b7d2 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -639,6 +639,7 @@ struct Proc Lock *lockwait; Lock *lastlock; /* debugging */ + Lock *lastilock; /* debugging */ Mach *wired; Mach *mp; /* machine this process last ran on */ diff --git a/port/proc.c b/port/proc.c index 519f6a8b1f206ad65e9f88a45e9e209ccd8ad7c1..6844083d743276930a7ef0efd84d26049e7fc481 100644 --- a/port/proc.c +++ b/port/proc.c @@ -88,7 +88,9 @@ void sched(void) { if(m->ilockdepth) - panic("ilockdepth %d", m->ilockdepth); + panic("ilockdepth %d, last lock 0x%p at 0x%lux", + m->ilockdepth, up?up->lastilock:nil, + (up && up->lastilock)?up->lastilock->pc:0); if(up){ if(up->nlocks && up->state != Moribund){ diff --git a/port/taslock.c b/port/taslock.c index 6a7fc4555522bd7e30ae5c984568a0baa9bbf2f0..f6a69ccccddfb1203f1bdd9666d17a695ccc88c4 100644 --- a/port/taslock.c +++ b/port/taslock.c @@ -99,7 +99,7 @@ ilock(Lock *l) if(tas(&l->key) == 0){ m->ilockdepth++; if(up) - up->lastlock = l; + up->lastilock = l; l->sr = x; l->pc = pc; l->p = up; @@ -122,7 +122,7 @@ ilock(Lock *l) if(tas(&l->key) == 0){ m->ilockdepth++; if(up) - up->lastlock = l; + up->lastilock = l; l->sr = x; l->pc = pc; l->p = up;