boolean haschance(allinfo *a, item *i, int side) { register state *j, *m; register ptype p, w, r; stype pp, ww; if (a->d.size == 0) return FALSE; if (side == RIGHT) { if (a->d.fset->wsum <= a->c - i->w) return TRUE; p = a->ps; w = a->ws; a->pitested++; pp = i->p - a->z - 1; ww = i->w - a->c; r = -DET(pp, ww, p, w); for (j = a->d.fset, m = a->d.lset + 1; j != m; j++) { if (DET(j->psum, j->wsum, p, w) >= r) return TRUE; } } else { if (a->d.lset->wsum > a->c + i->w) return TRUE; p = a->pt; w = a->wt; a->pitested++; pp = -i->p - a->z - 1; ww = -i->w - a->c; r = -DET(pp, ww, p, w); for (j = a->d.lset, m = a->d.fset - 1; j != m; j--) { if (DET(j->psum, j->wsum, p, w) >= r) return TRUE; } } a->pireduced++; return FALSE; }
static boolean haschance(allinfo *a, item *i, int side) { register itype p, w; register state *j, *m; register stype pp, ww; if (a->d.size == 0) return FALSE; #ifdef HASCHANCE if (side == RIGHT) { if (a->d.fset->wsum <= a->c - i->w) return TRUE; p = a->ps; w = a->ws; pitested++; pp = i->p - a->z - 1; ww = i->w - a->c; for (j = a->d.fset, m = a->d.lset + 1; j != m; j++) { if (DET(j->psum + pp, j->wsum + ww, p, w) >= 0) return TRUE; } } else { if (a->d.lset->wsum > a->c + i->w) return TRUE; p = a->pt; w = a->wt; pitested++; pp = -i->p - a->z - 1; ww = -i->w - a->c; for (j = a->d.lset, m = a->d.fset - 1; j != m; j--) { if (DET(j->psum + pp, j->wsum + ww, p, w) >= 0) return TRUE; } } pireduced++; return FALSE; #else p = a->b->p; w = a->b->w; if (side == LEFT) { return (DET(a->psumb - i->p - a->z-1, a->wsumb - i->w - a->c, p, w) >= 0); } else { return (DET(a->psumb + i->p - a->z-1, a->wsumb + i->w - a->c, p, w) >= 0); } #endif }
void CHangingLamp::UpdateCL () { inherited::UpdateCL (); if(m_pPhysicsShell) m_pPhysicsShell->InterpolateGlobalTransform(&XFORM()); if (Alive() && light_render->get_active()){ if(Visual()) PKinematics(Visual())->CalculateBones(); // update T&R from light (main) bone Fmatrix xf; if (light_bone!=BI_NONE){ Fmatrix& M = smart_cast<CKinematics*>(Visual())->LL_GetTransform(light_bone); xf.mul (XFORM(),M); VERIFY(!fis_zero(DET(xf))); }else{ xf.set (XFORM()); } light_render->set_rotation (xf.k,xf.i); light_render->set_position (xf.c); if (glow_render)glow_render->set_position (xf.c); // update T&R from ambient bone if (light_ambient){ if (ambient_bone!=light_bone){ if (ambient_bone!=BI_NONE){ Fmatrix& M = smart_cast<CKinematics*>(Visual())->LL_GetTransform(ambient_bone); xf.mul (XFORM(),M); VERIFY(!fis_zero(DET(xf))); }else{ xf.set (XFORM()); } } light_ambient->set_rotation (xf.k,xf.i); light_ambient->set_position (xf.c); } if (lanim){ int frame; u32 clr = lanim->CalculateBGR(Device.fTimeGlobal,frame); // возвращает в формате BGR Fcolor fclr; fclr.set ((float)color_get_B(clr),(float)color_get_G(clr),(float)color_get_R(clr),1.f); fclr.mul_rgb (fBrightness/255.f); light_render->set_color (fclr); if (glow_render) glow_render->set_color (fclr); if (light_ambient) { fclr.mul_rgb (ambient_power); light_ambient->set_color(fclr); } } } }
bool CSurface3DTriangle::Fit(/*long No,*/ CSurface3DPoint &P1, CSurface3DPoint &P2, CSurface3DPoint &P3) { double a = DET(P2.y-P1.y,P2.z-P1.z,P3.y-P1.y,P3.z-P1.z); double b = DET(P2.z-P1.z,P2.x-P1.x,P3.z-P1.z,P3.x-P1.x); double c = DET(P2.x-P1.x,P2.y-P1.y,P3.x-P1.x,P3.y-P1.y); if (fabs(c) < 1.0e-30) return false; m_A = (a/c) * (-1.0); m_B = (b/c) * (-1.0); m_C = (a*P1.x + b*P1.y + c*P1.z)/c; //m_No = No; return true; }
void partsort(allinfo *a, item *f, item *l, stype ws, int what) { register ptype mp, mw; register item *i, *j, *m; register stype wi; register int d; d = l - f + 1; if (d < 1) errorx("negative interval in partsort"); if (d > MINMED) { m = median(f, l, (int) sqrt((double)d)); } else { if (d > 1) { m = f + d / 2; if (DET(f->p, f->w, m->p, m->w) < 0) SWAP(f, m); if (d > 2) { if (DET(m->p, m->w, l->p, l->w) < 0) { SWAP(m, l); if (DET(f->p, f->w, m->p, m->w) < 0) SWAP(f, m); } } } } if (d > 3) { mp = m->p; mw = m->w; i = f; j = l; wi = ws; for (;;) { do { wi += i->w; i++; } while (DET(i->p, i->w, mp, mw) > 0); do { j--; } while (DET(j->p, j->w, mp, mw) < 0); if (i > j) break; SWAP(i, j); } if (wi <= a->cstar) { if (what == SORTALL) partsort(a, f, i-1, ws, what); if (what == PARTIATE) push(a, LEFT, f, i-1); partsort(a, i, l, wi, what); } else { if (what == SORTALL) partsort(a, i, l, wi, what); if (what == PARTIATE) push(a, RIGHT, i, l); partsort(a, f, i-1, ws, what); } } if ((d <= 3) || (what == SORTALL)) { a->fpart = f; a->lpart = l; a->wfpart = ws; } }
static int __init myri_sbus_probe(void) { struct net_device *dev = NULL; struct sbus_bus *bus; struct sbus_dev *sdev = 0; static int called = 0; int cards = 0, v; #ifdef MODULE root_myri_dev = NULL; #endif if (called) return -ENODEV; called++; for_each_sbus(bus) { for_each_sbusdev(sdev, bus) { if (cards) dev = NULL; if (myri_sbus_match(sdev)) { cards++; DET(("Found myricom myrinet as %s\n", sdev->prom_name)); if ((v = myri_ether_init(dev, sdev, (cards - 1)))) return v; } } } if (!cards) return -ENODEV; return 0; }
/* determines new minimum and new maximum * DetMinMax* (* = all cell representation) analyzes * an array of cells and adjust the min and max argument * if necessary. If min and max are not yet set then they * must be MV both. The function * assumes that both min and max are MV if min is MV. */ static void DetMinMaxUINT1( UINT1 *min, /* read-write. adjusted minimum */ UINT1 *max, /* read-write. adjusted maximum */ size_t nrCells,/* number of cells in buf */ const UINT1 *buf) /* cell values to be examined */ { DET(min, max, nrCells, buf, UINT1); }
/* determines new minimum and new maximum * DetMinMax* (* = all cell representation) analyzes * an array of cells and adjust the min and max argument * if necessary. If min and max are not yet set then they * must be MV both. The function * assumes that both min and max are MV if min is MV. */ static void DetMinMaxINT4( INT4 *min, /* read-write. adjusted minimum */ INT4 *max, /* read-write. adjusted maximum */ size_t nrCells,/* number of cells in buf */ const INT4 *buf) /* cell values to be examined */ { DET(min, max, nrCells, buf, INT4); }
TVec4 cross(const TVec4 &a, const TVec4 &b, const TVec4 &c) { TVec4 result; // XXX can this be improved? Look at assembly. #define ROW(i) a[i], b[i], c[i] #define DET(i,j,k) dot(TVec3(ROW(i)), cross(TVec3(ROW(j)), TVec3(ROW(k)))) result[0] = DET(1,2,3); result[1] = -DET(0,2,3); result[2] = DET(0,1,3); result[3] = -DET(0,1,2); return(result); #undef ROW #undef DET }
static void partsort(allinfo *a, item *f, item *l, stype ws, stype c, int what) { register itype mp, mw; register item *i, *j, *m; register stype wi; int d; d = l - f + 1; if (d > 1) { m = f + d / 2; if (DET(f->p, f->w, m->p, m->w) < 0) SWAP(f, m); if (d > 2) { if (DET(m->p, m->w, l->p, l->w) < 0) { SWAP(m, l); if (DET(f->p, f->w, m->p, m->w) < 0) SWAP(f, m); } } } if (d > 3) { mp = m->p; mw = m->w; i = f; j = l; wi = ws; for (;;) { do { wi += i->w; i++; } while (DET(i->p, i->w, mp, mw) > 0); do { j--; } while (DET(j->p, j->w, mp, mw) < 0); if (i > j) break; SWAP(i, j); } if (wi <= c) { if (what == SORTALL) partsort(a, f, i-1, ws, c, what); if (what == PARTITION) push(a, LEFT, f, i-1); partsort(a, i, l, wi, c, what); } else { if (what == SORTALL) partsort(a, i, l, wi, c, what); if (what == PARTITION) push(a, RIGHT, i, l); partsort(a, f, i-1, ws, c, what); } } if ((d <= 3) || (what == SORTALL)) { a->fpart = f; a->lpart = l; a->wfpart = ws; } }
item *median(item *f1, item *l1, ntype s) { /* Find median r of items [f1, f1+s, f1+2s, ... l1], */ /* and ensure the ordering f1 >= r >= l1. */ register ptype mp, mw; register item *i, *j; register item *f, *l, *k, *m, *q; ntype n, d; static item r; n = (l1 - f1) / s; /* number of values */ f = f1; /* calculated first item */ l = f1 + s * n; /* calculated last item */ k = l; /* saved last item */ q = f + s * (n / 2); /* middle value */ for (;;) { d = (l - f + s) / s; m = f + s * (d / 2); if (d > 1) { if (DET(f->p, f->w, m->p, m->w) < 0) SWAP(f, m); if (d > 2) { if (DET(m->p, m->w, l->p, l->w) < 0) { SWAP(m, l); if (DET(f->p, f->w, m->p, m->w) < 0) SWAP(f, m); } } } if (d <= 3) { r = *q; break; } r.p = mp = m->p; r.w = mw = m->w; i = f; j = l; for (;;) { do { i += s; } while (DET(i->p, i->w, mp, mw) > 0); do { j -= s; } while (DET(j->p, j->w, mp, mw) < 0); if (i > j) break; SWAP(i, j); } if ((j <= q) && (q <= i)) break; if (i > q) l = j; else f = i; } SWAP(k, l1); return &r; }
void CCar::cb_Steer (CBoneInstance* B) { VERIFY2(fsimilar(DET(B->mTransform),1.f,DET_CHECK_EPS),"Bones receive returns 0 matrix"); CCar* C = static_cast<CCar*>(B->callback_param()); Fmatrix m; m.rotateZ(C->m_steer_angle); B->mTransform.mulB_43 (m); #ifdef DEBUG if( !fsimilar(DET(B->mTransform),1.f,DET_CHECK_EPS) ){ Log("RotatingZ angle=",C->m_steer_angle); VERIFY2(0,"Bones callback returns BAD!!! matrix"); } #endif }
static void rudidiv(allinfo *a) { register item *i, *m, *b; register itype x, y, r; register prod pb, wb, q; register stype ws; b = a->b; pb = b->p; wb = b->w; q = DET(a->z+1-a->psumb, a->c-a->wsumb, pb, wb); x = a->fitem->w; ws = 0; for (i = a->fitem, m = a->litem+1; i != m; i++) { if ((i < b) && (DET(-i->p, -i->w, pb, wb) < q)) { ws += i->w; continue; } if ((i > b) && (DET(i->p, i->w, pb, wb) < q)) { continue; } y = x; x = i->w; while (y != 0) { r = x % y; x = y; y = r; } if (x == 1) return; } a->c = ws + x * ((a->c-ws) / x); }
//==========================================================================* // Result := Curvature (Inverse radius) //--------------------------------------------------------------------------* double Curv(double X1, double Y1, double X2, double Y2, double X3, double Y3) { double Px = X1 - X2; double Py = Y1 - Y2; double Qx = X2 - X3; double Qy = Y2 - Y3; double Rx = X3 - X1; double Ry = Y3 - Y1; return ((2 * (Px * Qy - Py * Qx)) / DET(Px,Py,Qx,Qy,Rx,Ry)); }
static void sursort(item *f, item *l, itype sur, stype c, stype *p1, stype *w1, item **b) { register itype s; register prod mp, mw; register item *i, *j, *m; register stype ws, ps; static item nn; item *l1; stype psum; int d; psum = 0; s = sur; l1 = l + 1; for (;;) { d = l - f + 1; if (d > 1) { m = f + d / 2; if (DET(f->p, f->w+s, m->p, m->w+s) < 0) SWAP(f, m); if (d > 2) { if (DET(m->p, m->w+s, l->p, l->w+s) < 0) { SWAP(m, l); if (DET(f->p, f->w+s, m->p, m->w+s) < 0) SWAP(f, m); } } } if (d <= 3) break; mp = m->p; mw = m->w+s; i = f; j = l; ws = ps = 0; for (;;) { do { ws+=i->w+s; ps+=i->p; i++; } while (DET(i->p,i->w+s,mp,mw) > 0); do { j--; } while (DET(j->p,j->w+s,mp,mw) < 0); if (i > j) break; SWAP(i, j); } if (ws <= c) { f = i; c -= ws; psum += ps; } else l = i-1; } for ( ; f != l1; f++) { if (f->w+s > c) { *p1 = psum; *w1 = c; *b = f; return; } c -= f->w+s; psum += f->p; } nn.p = 0; nn.w = 1; *p1 = psum; *w1 = c; *b = &nn; }
static void reduceset(allinfo *a) { register state *i, *m, *k; register stype c, z; register prod p, w; state *v, *r1, *rm; boolean atstart, atend; if (a->d.size == 0) return; /* find break point and improve solution */ r1 = a->d.fset; rm = a->d.lset; v = findvect(a->c, r1, rm); if (v == NULL) v = r1 - 1; else if (v->psum > a->z) improvesol(a, v); /* expand core, and choose ps, ws, pt, wt */ expandcore(a, &atstart, &atend); /* now do the reduction */ /* NB! This is the most efficient implementation, no product q is needed */ c = a->c; z = a->z + 1; k = a->d.setm; if (!atstart) { p = a->ps; w = a->ws; for (i = rm, m = v; i != m; i--) { if (DET(i->psum-z, i->wsum-c, p, w) >= 0) { k--; *k = *i; } } } if (!atend) { p = a->pt; w = a->wt; for (i = v, m = r1 - 1; i != m; i--) { if (DET(i->psum-z, i->wsum-c, p, w) >= 0) { k--; *k = *i; } } } /* save limit */ a->d.fset = k; a->d.lset = a->d.setm - 1; /* reserve one record for multiplication */ a->d.size = DIFF(a->d.fset, a->d.lset); }
void simpreduce(int side, item **f, item **l, allinfo *a) { register item *i, *j, *k; register ptype pb, wb; register ptype q, r; register int redu; if (a->d.size == 0) { *f = *l+1; return; } if (*l < *f) return; pb = a->b->p; wb = a->b->w; q = DET(a->z+1-a->psumb, a->c-a->wsumb, pb, wb); r = -DET(a->z+1-a->psumb, a->c-a->wsumb, pb, wb); i = *f; j = *l; redu = 0; if (side == LEFT) { k = a->fsort - 1; while (i <= j) { if (DET(j->p, j->w, pb, wb) > r) { SWAP(i, j); i++; redu++; /* not feasible */ } else { SWAP(j, k); j--; k--; /* feasible */ } } *l = a->fsort - 1; *f = k + 1; } else { k = a->lsort + 1; while (i <= j) { if (DET(i->p, i->w, pb, wb) < q) { SWAP(i, j); j--; redu++; /* not feasible */ } else { SWAP(i, k); i++; k++; /* feasible */ } } *f = a->lsort + 1; *l = k - 1; } a->simpreduced += redu; }
static void simpreduce(int side, item **f, item **l, allinfo *a) { register item *i, *j, *k; register prod pb, wb; register prod q; register int red; if (a->d.size == 0) { *f = *l+1; return; } if (*l < *f) return; pb = a->b->p; wb = a->b->w; q = DET(a->z+1-a->psumb, a->c-a->wsumb, pb, wb); i = *f; j = *l; red = 0; if (side == LEFT) { k = a->fsort - 1; while (i != j+1) { if (DET(-j->p, -j->w, pb, wb) < q) { SWAP(i, j); i++; /* not feasible */ red++; } else { SWAP(j, k); j--; k--; /* feasible */ } } *l = a->fsort - 1; *f = k + 1; } else { k = a->lsort + 1; while (i != j+1) { if (DET(i->p, i->w, pb, wb) < q) { SWAP(i, j); j--; /* not feasible */ red++; } else { SWAP(i, k); i++; k++; /* feasible */ } } *f = a->lsort + 1; *l = k - 1; } if (a->master) simpreduced += red; }
static int myri_do_handshake(struct myri_eth *mp) { struct myri_shmem __iomem *shmem = mp->shmem; void __iomem *cregs = mp->cregs; struct myri_channel __iomem *chan = &shmem->channel; int tick = 0; DET(("myri_do_handshake: ")); if (sbus_readl(&chan->state) == STATE_READY) { DET(("Already STATE_READY, failed.\n")); return -1; /* We're hosed... */ } myri_disable_irq(mp->lregs, cregs); while (tick++ < 25) { u32 softstate; /* Wake it up. */ DET(("shakedown, CONTROL_WON, ")); sbus_writel(1, &shmem->shakedown); sbus_writel(CONTROL_WON, cregs + MYRICTRL_CTRL); softstate = sbus_readl(&chan->state); DET(("chanstate[%08x] ", softstate)); if (softstate == STATE_READY) { DET(("wakeup successful, ")); break; } if (softstate != STATE_WFN) { DET(("not WFN setting that, ")); sbus_writel(STATE_WFN, &chan->state); } udelay(20); } myri_enable_irq(mp->lregs, cregs); if (tick > 25) { DET(("25 ticks we lose, failure.\n")); return -1; } DET(("success\n")); return 0; }
int DET(int A[], int order) { if (order == 2) { return (A[0] * A[3] - A[2] * A[1]); } int k, sum, factor, det; factor = -1; sum = 0; for (k = 0; k < order; k++) { factor = factor * -1; int *min = matminor(A, k, order - 1); det = DET(min, order - 1); free (min); sum = sum + (factor * A[k]* det); } return sum; }
void CHelicopter::UpdateHeliParticles () { CKinematics* K = smart_cast<CKinematics*>(Visual()); m_particleXFORM = K->LL_GetTransform(m_smoke_bone); m_particleXFORM.mulA_43(XFORM()); if (m_pParticle){ Fvector vel; Fvector last_pos = PositionStack.back().vPosition; vel.sub(Position(), last_pos); vel.mul(5.0f); m_pParticle->UpdateParent(m_particleXFORM, vel ); } //lighting if(m_light_render->get_active()){ Fmatrix xf; Fmatrix& M = K->LL_GetTransform(u16(m_light_bone)); xf.mul (XFORM(),M); VERIFY(!fis_zero(DET(xf))); m_light_render->set_rotation (xf.k,xf.i); m_light_render->set_position (xf.c); if (m_lanim) { int frame; u32 clr = m_lanim->CalculateBGR(Device.fTimeGlobal,frame); // òþ÷ò¨ð•ðõª ò ¯þ¨üðªõ BGR Fcolor fclr; fclr.set ((float)color_get_B(clr),(float)color_get_G(clr),(float)color_get_R(clr),1.f); fclr.mul_rgb (m_light_brightness/255.f); m_light_render->set_color (fclr); } } }
bool CIKFoot::GetFootStepMatrix( ik_goal_matrix &m, const Fmatrix &g_anim, const SIKCollideData &cld, bool collide, bool rotation, bool b_make_shift/*=true*/ )const { const Fmatrix global_anim = g_anim; Fvector local_point; ToePosition( local_point ); //toe position in bone[2] space Fvector global_point; global_anim.transform_tiny( global_point, local_point ); //non collided toe in global space Fvector foot_normal; FootNormal( foot_normal ); global_anim.transform_dir( foot_normal ); #ifdef DEBUG //if( ph_dbg_draw_mask.test( phDbgDrawIKGoal ) ) //{ // DBG_DrawLine( global_point, Fvector().add( global_point, foot_normal ), D3DCOLOR_XRGB( 0, 255, 255) ); //} #endif if( cld.m_collide_point == ik_foot_geom::heel || cld.m_collide_point == ik_foot_geom::side ) { Fmatrix foot;ref_bone_to_foot( foot, g_anim ); Fvector heel; HeelPosition( heel ); foot.transform_tiny(global_point, heel ); #ifdef DEBUG if( ph_dbg_draw_mask.test( phDbgDrawIKGoal ) ) DBG_DrawPoint( global_point, 0.01, D3DCOLOR_XRGB( 0, 255, 255)); #endif Fmatrix foot_to_ref; ref_bone_to_foot_transform(foot_to_ref).transform_tiny(local_point, heel ); } float dtoe_tri =-cld.m_plane.d - cld.m_plane.n.dotproduct( global_point ); if( !cld.collided || _abs( dtoe_tri ) > collide_dist ) { m.set( global_anim, ik_goal_matrix::cl_free ); return false; } Fplane p = cld.m_plane; Fmatrix xm; xm.set( global_anim ); ik_goal_matrix::e_collide_state cl_state = ik_goal_matrix::cl_undefined; if( rotation )//!collide || ik_allign_free_foot cl_state = rotate( xm, p, foot_normal, global_point, collide ); if( b_make_shift && make_shift( xm, local_point, collide, p, cld.m_pick_dir ) ) switch( cl_state ) { case ik_goal_matrix::cl_aligned : break; case ik_goal_matrix::cl_undefined : case ik_goal_matrix::cl_free : cl_state = ik_goal_matrix::cl_translational; break; case ik_goal_matrix::cl_rotational: cl_state = ik_goal_matrix::cl_mixed; break; default: NODEFAULT; } else if( cl_state == ik_goal_matrix::cl_undefined ) cl_state = ik_goal_matrix::cl_free; VERIFY( _valid( xm ) ); m.set( xm, cl_state ); #ifdef DEBUG if(ph_dbg_draw_mask.test( phDbgDrawIKGoal )) { DBG_DrawPoint( global_point, 0.03f, D3DCOLOR_RGBA( 255, 0, 0, 255 ) ); } if(!fsimilar( _abs( DET( g_anim ) - 1.f ), _abs( DET( m.get() ) - 1.f ), 0.001f ) ) Msg("scale g_anim: %f scale m: %f ", DET( g_anim ) , DET( m.get() ) ); #endif return true; }
void CWeapon::UpdatePosition(const Fmatrix& trans) { Position().set (trans.c); XFORM().mul (trans,m_strapped_mode ? m_StrapOffset : m_Offset); VERIFY (!fis_zero(DET(renderable.xform))); }
/* update ellipsoid according to the given motion */ void ELLIP_Update (ELLIP *eli, void *body, void *shp, MOTION motion) { SGP sgp = {shp, eli, GOBJ_ELLIP, NULL}; double *ref = eli->ref_center, (*ref_pnt) [3] = eli->ref_point, *cur = eli->cur_center, (*cur_pnt) [3] = eli->cur_point; if (motion) { motion (body, &sgp, ref, cur); motion (body, &sgp, ref_pnt [0], cur_pnt [0]); motion (body, &sgp, ref_pnt [1], cur_pnt [1]); motion (body, &sgp, ref_pnt [2], cur_pnt [2]); BODY *bod = body; switch (bod->kind) { case OBS: case RIG: { double *R1 = bod->conf, *R0 = eli->ref_rot, *rot = eli->cur_rot; NNMUL (R1, R0, rot); } break; case PRB: { double *F = bod->conf, *sca0 = eli->ref_sca, *rot0 = eli->ref_rot, *sca1 = eli->cur_sca, *rot1 = eli->cur_rot; double U[9] = {1.0/(sca0[0]*sca0[0]), 0.0, 0.0, 0.0, 1.0/(sca0[1]*sca0[1]), 0.0, 0.0, 0.0, 1.0/(sca0[2]*sca0[2])}; double A0[9], iF[9], det, X[3], Y[9], A[9]; NTMUL (U, rot0, Y); NNMUL (rot0, Y, A0); TNCOPY (F, Y); /* T --> since deformation gradient is stored row-wise */ INVERT (Y, iF, det); ASSERT_TEXT (det > 0.0, "det(F) <= 0.0 during ellipsoid update"); NNMUL (A0, iF, Y); TNMUL (iF, Y, A); ASSERT_TEXT (lapack_dsyev ('V', 'U', 3, A, 3, X, Y, 9) == 0, "Eigen decomposition failed during ellipsoid update"); if (DET(A) < 0.0) /* det(A) is 1.0 or -1.0 */ { SCALE9 (A, -1.0); /* keep positive space orientation */ } NNCOPY (A, rot1); sca1[0] = 1.0/sqrt(X[0]); sca1[1] = 1.0/sqrt(X[1]); sca1[2] = 1.0/sqrt(X[2]); } break; default: { ASSERT_TEXT (0, "Invalid body kind during ellipsoid update"); } break; } } else { COPY (ref, cur); COPY (ref_pnt [0], cur_pnt [0]); COPY (ref_pnt [1], cur_pnt [1]); COPY (ref_pnt [2], cur_pnt [2]); sca_rot (eli->ref_center, eli->ref_point, eli->ref_sca, eli->ref_rot); COPY (eli->ref_sca, eli->cur_sca); NNCOPY (eli->ref_rot, eli->cur_rot); } }
static int __devinit myri_sbus_probe(struct platform_device *op) { struct device_node *dp = op->dev.of_node; static unsigned version_printed; struct net_device *dev; struct myri_eth *mp; const void *prop; static int num; int i, len; DET(("myri_ether_init(%p,%d):\n", op, num)); dev = alloc_etherdev(sizeof(struct myri_eth)); if (!dev) return -ENOMEM; if (version_printed++ == 0) ; SET_NETDEV_DEV(dev, &op->dev); mp = netdev_priv(dev); spin_lock_init(&mp->irq_lock); mp->myri_op = op; /* Clean out skb arrays. */ for (i = 0; i < (RX_RING_SIZE + 1); i++) mp->rx_skbs[i] = NULL; for (i = 0; i < TX_RING_SIZE; i++) mp->tx_skbs[i] = NULL; /* First check for EEPROM information. */ prop = of_get_property(dp, "myrinet-eeprom-info", &len); if (prop) memcpy(&mp->eeprom, prop, sizeof(struct myri_eeprom)); if (!prop) { /* No eeprom property, must cook up the values ourselves. */ DET(("No EEPROM: ")); mp->eeprom.bus_type = BUS_TYPE_SBUS; mp->eeprom.cpuvers = of_getintprop_default(dp, "cpu_version", 0); mp->eeprom.cval = of_getintprop_default(dp, "clock_value", 0); mp->eeprom.ramsz = of_getintprop_default(dp, "sram_size", 0); if (!mp->eeprom.cpuvers) mp->eeprom.cpuvers = CPUVERS_2_3; if (mp->eeprom.cpuvers < CPUVERS_3_0) mp->eeprom.cval = 0; if (!mp->eeprom.ramsz) mp->eeprom.ramsz = (128 * 1024); prop = of_get_property(dp, "myrinet-board-id", &len); if (prop) memcpy(&mp->eeprom.id[0], prop, 6); else set_boardid_from_idprom(mp, num); prop = of_get_property(dp, "fpga_version", &len); if (prop) memcpy(&mp->eeprom.fvers[0], prop, 32); else memset(&mp->eeprom.fvers[0], 0, 32); if (mp->eeprom.cpuvers == CPUVERS_4_1) { if (mp->eeprom.ramsz == (128 * 1024)) mp->eeprom.ramsz = (256 * 1024); if ((mp->eeprom.cval == 0x40414041) || (mp->eeprom.cval == 0x90449044)) mp->eeprom.cval = 0x50e450e4; } } #ifdef DEBUG_DETECT dump_eeprom(mp); #endif for (i = 0; i < 6; i++) dev->dev_addr[i] = mp->eeprom.id[i]; determine_reg_space_size(mp); /* Map in the MyriCOM register/localram set. */ if (mp->eeprom.cpuvers < CPUVERS_4_0) { /* XXX Makes no sense, if control reg is non-existent this * XXX driver cannot function at all... maybe pre-4.0 is * XXX only a valid version for PCI cards? Ask feldy... */ DET(("Mapping regs for cpuvers < CPUVERS_4_0\n")); mp->regs = of_ioremap(&op->resource[0], 0, mp->reg_size, "MyriCOM Regs"); if (!mp->regs) { ; goto err; } mp->lanai = mp->regs + (256 * 1024); mp->lregs = mp->lanai + (0x10000 * 2); } else { DET(("Mapping regs for cpuvers >= CPUVERS_4_0\n")); mp->cregs = of_ioremap(&op->resource[0], 0, PAGE_SIZE, "MyriCOM Control Regs"); mp->lregs = of_ioremap(&op->resource[0], (256 * 1024), PAGE_SIZE, "MyriCOM LANAI Regs"); mp->lanai = of_ioremap(&op->resource[0], (512 * 1024), mp->eeprom.ramsz, "MyriCOM SRAM"); } DET(("Registers mapped: cregs[%p] lregs[%p] lanai[%p]\n", mp->cregs, mp->lregs, mp->lanai)); if (mp->eeprom.cpuvers >= CPUVERS_4_0) mp->shmem_base = 0xf000; else mp->shmem_base = 0x8000; DET(("Shared memory base is %04x, ", mp->shmem_base)); mp->shmem = (struct myri_shmem __iomem *) (mp->lanai + (mp->shmem_base * 2)); DET(("shmem mapped at %p\n", mp->shmem)); mp->rqack = &mp->shmem->channel.recvqa; mp->rq = &mp->shmem->channel.recvq; mp->sq = &mp->shmem->channel.sendq; /* Reset the board. */ DET(("Resetting LANAI\n")); myri_reset_off(mp->lregs, mp->cregs); myri_reset_on(mp->cregs); /* Turn IRQ's off. */ myri_disable_irq(mp->lregs, mp->cregs); /* Reset once more. */ myri_reset_on(mp->cregs); /* Get the supported DVMA burst sizes from our SBUS. */ mp->myri_bursts = of_getintprop_default(dp->parent, "burst-sizes", 0x00); if (!sbus_can_burst64()) mp->myri_bursts &= ~(DMA_BURST64); DET(("MYRI bursts %02x\n", mp->myri_bursts)); /* Encode SBUS interrupt level in second control register. */ i = of_getintprop_default(dp, "interrupts", 0); if (i == 0) i = 4; DET(("prom_getint(interrupts)==%d, irqlvl set to %04x\n", i, (1 << i))); sbus_writel((1 << i), mp->cregs + MYRICTRL_IRQLVL); mp->dev = dev; dev->watchdog_timeo = 5*HZ; dev->irq = op->archdata.irqs[0]; dev->netdev_ops = &myri_ops; /* Register interrupt handler now. */ DET(("Requesting MYRIcom IRQ line.\n")); if (request_irq(dev->irq, myri_interrupt, IRQF_SHARED, "MyriCOM Ethernet", (void *) dev)) { ; goto err; } dev->mtu = MYRINET_MTU; dev->header_ops = &myri_header_ops; dev->hard_header_len = (ETH_HLEN + MYRI_PAD_LEN); /* Load code onto the LANai. */ DET(("Loading LANAI firmware\n")); if (myri_load_lanai(mp)) { ; goto err_free_irq; } if (register_netdev(dev)) { ; goto err_free_irq; } dev_set_drvdata(&op->dev, mp); num++; // printk("%s: MyriCOM MyriNET Ethernet %pM\n", ; return 0; err_free_irq: free_irq(dev->irq, dev); err: /* This will also free the co-allocated private data*/ free_netdev(dev); return -ENODEV; }
static int __init myri_ether_init(struct net_device *dev, struct sbus_dev *sdev, int num) { static unsigned version_printed = 0; struct myri_eth *mp; unsigned char prop_buf[32]; int i; DET(("myri_ether_init(%p,%p,%d):\n", dev, sdev, num)); dev = init_etherdev(0, sizeof(struct myri_eth)); if (version_printed++ == 0) printk(version); printk("%s: MyriCOM MyriNET Ethernet ", dev->name); mp = (struct myri_eth *) dev->priv; mp->myri_sdev = sdev; /* Clean out skb arrays. */ for (i = 0; i < (RX_RING_SIZE + 1); i++) mp->rx_skbs[i] = NULL; for (i = 0; i < TX_RING_SIZE; i++) mp->tx_skbs[i] = NULL; /* First check for EEPROM information. */ i = prom_getproperty(sdev->prom_node, "myrinet-eeprom-info", (char *)&mp->eeprom, sizeof(struct myri_eeprom)); DET(("prom_getprop(myrinet-eeprom-info) returns %d\n", i)); if (i == 0 || i == -1) { /* No eeprom property, must cook up the values ourselves. */ DET(("No EEPROM: ")); mp->eeprom.bus_type = BUS_TYPE_SBUS; mp->eeprom.cpuvers = prom_getintdefault(sdev->prom_node,"cpu_version",0); mp->eeprom.cval = prom_getintdefault(sdev->prom_node,"clock_value",0); mp->eeprom.ramsz = prom_getintdefault(sdev->prom_node,"sram_size",0); DET(("cpuvers[%d] cval[%d] ramsz[%d]\n", mp->eeprom.cpuvers, mp->eeprom.cval, mp->eeprom.ramsz)); if (mp->eeprom.cpuvers == 0) { DET(("EEPROM: cpuvers was zero, setting to %04x\n",CPUVERS_2_3)); mp->eeprom.cpuvers = CPUVERS_2_3; } if (mp->eeprom.cpuvers < CPUVERS_3_0) { DET(("EEPROM: cpuvers < CPUVERS_3_0, clockval set to zero.\n")); mp->eeprom.cval = 0; } if (mp->eeprom.ramsz == 0) { DET(("EEPROM: ramsz == 0, setting to 128k\n")); mp->eeprom.ramsz = (128 * 1024); } i = prom_getproperty(sdev->prom_node, "myrinet-board-id", &prop_buf[0], 10); DET(("EEPROM: prom_getprop(myrinet-board-id) returns %d\n", i)); if ((i != 0) && (i != -1)) memcpy(&mp->eeprom.id[0], &prop_buf[0], 6); else set_boardid_from_idprom(mp, num); i = prom_getproperty(sdev->prom_node, "fpga_version", &mp->eeprom.fvers[0], 32); DET(("EEPROM: prom_getprop(fpga_version) returns %d\n", i)); if (i == 0 || i == -1) memset(&mp->eeprom.fvers[0], 0, 32); if (mp->eeprom.cpuvers == CPUVERS_4_1) { DET(("EEPROM: cpuvers CPUVERS_4_1, ")); if (mp->eeprom.ramsz == (128 * 1024)) { DET(("ramsize 128k, setting to 256k, ")); mp->eeprom.ramsz = (256 * 1024); } if ((mp->eeprom.cval==0x40414041)||(mp->eeprom.cval==0x90449044)){ DET(("changing cval from %08x to %08x ", mp->eeprom.cval, 0x50e450e4)); mp->eeprom.cval = 0x50e450e4; } DET(("\n")); } } #ifdef DEBUG_DETECT dump_eeprom(mp); #endif for (i = 0; i < 6; i++) printk("%2.2x%c", dev->dev_addr[i] = mp->eeprom.id[i], i == 5 ? ' ' : ':'); printk("\n"); determine_reg_space_size(mp); /* Map in the MyriCOM register/localram set. */ if (mp->eeprom.cpuvers < CPUVERS_4_0) { /* XXX Makes no sense, if control reg is non-existant this * XXX driver cannot function at all... maybe pre-4.0 is * XXX only a valid version for PCI cards? Ask feldy... */ DET(("Mapping regs for cpuvers < CPUVERS_4_0\n")); mp->regs = sbus_ioremap(&sdev->resource[0], 0, mp->reg_size, "MyriCOM Regs"); if (!mp->regs) { printk("MyriCOM: Cannot map MyriCOM registers.\n"); return -ENODEV; } mp->lanai = (unsigned short *) (mp->regs + (256 * 1024)); mp->lanai3 = (unsigned int *) mp->lanai; mp->lregs = (unsigned long) &mp->lanai[0x10000]; } else { DET(("Mapping regs for cpuvers >= CPUVERS_4_0\n")); mp->cregs = sbus_ioremap(&sdev->resource[0], 0, PAGE_SIZE, "MyriCOM Control Regs"); mp->lregs = sbus_ioremap(&sdev->resource[0], (256 * 1024), PAGE_SIZE, "MyriCOM LANAI Regs"); mp->lanai = (unsigned short *) sbus_ioremap(&sdev->resource[0], (512 * 1024), mp->eeprom.ramsz, "MyriCOM SRAM"); mp->lanai3 = (unsigned int *) mp->lanai; } DET(("Registers mapped: cregs[%lx] lregs[%lx] lanai[%p] lanai3[%p]\n", mp->cregs, mp->lregs, mp->lanai, mp->lanai3)); if (mp->eeprom.cpuvers >= CPUVERS_4_0) mp->shmem_base = 0xf000; else mp->shmem_base = 0x8000; DET(("Shared memory base is %04x, ", mp->shmem_base)); mp->shmem = (struct myri_shmem *) &mp->lanai[mp->shmem_base]; DET(("shmem mapped at %p\n", mp->shmem)); mp->rqack = &mp->shmem->channel.recvqa; mp->rq = &mp->shmem->channel.recvq; mp->sq = &mp->shmem->channel.sendq; /* Reset the board. */ DET(("Resetting LANAI\n")); myri_reset_off(mp->lregs, mp->cregs); myri_reset_on(mp->cregs); /* Turn IRQ's off. */ myri_disable_irq(mp->lregs, mp->cregs); /* Reset once more. */ myri_reset_on(mp->cregs); /* Get the supported DVMA burst sizes from our SBUS. */ mp->myri_bursts = prom_getintdefault(mp->myri_sdev->bus->prom_node, "burst-sizes", 0x00); if (!sbus_can_burst64(sdev)) mp->myri_bursts &= ~(DMA_BURST64); DET(("MYRI bursts %02x\n", mp->myri_bursts)); /* Encode SBUS interrupt level in second control register. */ i = prom_getint(sdev->prom_node, "interrupts"); if (i == 0) i = 4; DET(("prom_getint(interrupts)==%d, irqlvl set to %04x\n", i, (1 << i))); sbus_writel((1 << i), mp->cregs + MYRICTRL_IRQLVL); mp->dev = dev; dev->open = &myri_open; dev->stop = &myri_close; dev->hard_start_xmit = &myri_start_xmit; dev->tx_timeout = &myri_tx_timeout; dev->watchdog_timeo = 5*HZ; dev->get_stats = &myri_get_stats; dev->set_multicast_list = &myri_set_multicast; dev->irq = sdev->irqs[0]; /* Register interrupt handler now. */ DET(("Requesting MYRIcom IRQ line.\n")); if (request_irq(dev->irq, &myri_interrupt, SA_SHIRQ, "MyriCOM Ethernet", (void *) dev)) { printk("MyriCOM: Cannot register interrupt handler.\n"); return -ENODEV; } DET(("ether_setup()\n")); ether_setup(dev); dev->mtu = MYRINET_MTU; dev->change_mtu = myri_change_mtu; dev->hard_header = myri_header; dev->rebuild_header = myri_rebuild_header; dev->hard_header_len = (ETH_HLEN + MYRI_PAD_LEN); dev->hard_header_cache = myri_header_cache; dev->header_cache_update= myri_header_cache_update; /* Load code onto the LANai. */ DET(("Loading LANAI firmware\n")); myri_load_lanai(mp); #ifdef MODULE dev->ifindex = dev_new_index(); mp->next_module = root_myri_dev; root_myri_dev = mp; #endif return 0; }
BOOL CGameObject::net_Spawn (CSE_Abstract* DC) { VERIFY (!m_spawned); m_spawned = true; m_spawn_time = Device.dwFrame; m_ai_obstacle = xr_new<ai_obstacle>(this); CSE_Abstract *E = (CSE_Abstract*)DC; VERIFY (E); const CSE_Visual *visual = smart_cast<const CSE_Visual*>(E); if (visual) { cNameVisual_set (visual_name(E)); if (visual->flags.test(CSE_Visual::flObstacle)) { ISpatial *self = smart_cast<ISpatial*>(this); self->spatial.type |= STYPE_OBSTACLE; } } // Naming cName_set (E->s_name); cNameSect_set (E->s_name); if (E->name_replace()[0]) cName_set (E->name_replace()); bool demo_spectator = false; if (Level().IsDemoPlayStarted() && E->ID == u16(-1)) { Msg("* Spawning demo spectator ..."); demo_spectator = true; } else { R_ASSERT(Level().Objects.net_Find(E->ID) == NULL); } setID (E->ID); // if (GameID() != eGameIDSingle) // Msg ("CGameObject::net_Spawn -- object %s[%x] setID [%d]", *(E->s_name), this, E->ID); // XForm XFORM().setXYZ (E->o_Angle); Position().set (E->o_Position); #ifdef DEBUG if(ph_dbg_draw_mask1.test(ph_m1_DbgTrackObject)&&stricmp(PH_DBG_ObjectTrackName(),*cName())==0) { Msg("CGameObject::net_Spawn obj %s Position set from CSE_Abstract %f,%f,%f",PH_DBG_ObjectTrackName(),Position().x,Position().y,Position().z); } #endif VERIFY (_valid(renderable.xform)); VERIFY (!fis_zero(DET(renderable.xform))); CSE_ALifeObject *O = smart_cast<CSE_ALifeObject*>(E); if (O && xr_strlen(O->m_ini_string)) { #pragma warning(push) #pragma warning(disable:4238) m_ini_file = xr_new<CInifile>( &IReader ( (void*)(*(O->m_ini_string)), O->m_ini_string.size() ), FS.get_path("$game_config$")->m_Path ); #pragma warning(pop) } m_story_id = ALife::_STORY_ID(-1); if (O) m_story_id = O->m_story_id; // Net params setLocal (E->s_flags.is(M_SPAWN_OBJECT_LOCAL)); if (Level().IsDemoPlay()) //&& OnClient()) { if (!demo_spectator) { setLocal(FALSE); } }; setReady (TRUE); if (!demo_spectator) g_pGameLevel->Objects.net_Register (this); m_server_flags.one (); if (O) { m_server_flags = O->m_flags; if (O->m_flags.is(CSE_ALifeObject::flVisibleForAI)) spatial.type |= STYPE_VISIBLEFORAI; else spatial.type = (spatial.type | STYPE_VISIBLEFORAI) ^ STYPE_VISIBLEFORAI; } reload (*cNameSect()); if(!g_dedicated_server) CScriptBinder::reload (*cNameSect()); reinit (); if(!g_dedicated_server) CScriptBinder::reinit (); #ifdef DEBUG if(ph_dbg_draw_mask1.test(ph_m1_DbgTrackObject)&&stricmp(PH_DBG_ObjectTrackName(),*cName())==0) { Msg("CGameObject::net_Spawn obj %s After Script Binder reinit %f,%f,%f",PH_DBG_ObjectTrackName(),Position().x,Position().y,Position().z); } #endif //load custom user data from server if(!E->client_data.empty()) { // Msg ("client data is present for object [%d][%s], load is processed",ID(),*cName()); IReader ireader = IReader(&*E->client_data.begin(), E->client_data.size()); net_Load (ireader); } else { // Msg ("no client data for object [%d][%s], load is skipped",ID(),*cName()); } // if we have a parent if ( ai().get_level_graph() ) { if ( E->ID_Parent == 0xffff ) { CSE_ALifeObject* l_tpALifeObject = smart_cast<CSE_ALifeObject*>(E); if (l_tpALifeObject && ai().level_graph().valid_vertex_id(l_tpALifeObject->m_tNodeID)) ai_location().level_vertex (l_tpALifeObject->m_tNodeID); else { CSE_Temporary* l_tpTemporary = smart_cast<CSE_Temporary*> (E); if (l_tpTemporary && ai().level_graph().valid_vertex_id(l_tpTemporary->m_tNodeID)) ai_location().level_vertex (l_tpTemporary->m_tNodeID); } if (l_tpALifeObject && ai().game_graph().valid_vertex_id(l_tpALifeObject->m_tGraphID)) ai_location().game_vertex (l_tpALifeObject->m_tGraphID); validate_ai_locations (false); // validating position if ( UsedAI_Locations() && ai().level_graph().inside( ai_location().level_vertex_id(), Position() ) && can_validate_position_on_spawn() ) Position().y = EPS_L + ai().level_graph().vertex_plane_y(*ai_location().level_vertex(),Position().x,Position().z); } else { CSE_ALifeObject* const alife_object = smart_cast<CSE_ALifeObject*>(E); if ( alife_object && ai().level_graph().valid_vertex_id(alife_object->m_tNodeID) ) { ai_location().level_vertex (alife_object->m_tNodeID); ai_location().game_vertex (alife_object->m_tGraphID); } } } inherited::net_Spawn (DC); m_bObjectRemoved = false; spawn_supplies (); #ifdef DEBUG if(ph_dbg_draw_mask1.test(ph_m1_DbgTrackObject)&&stricmp(PH_DBG_ObjectTrackName(),*cName())==0) { Msg("CGameObject::net_Spawn obj %s Before CScriptBinder::net_Spawn %f,%f,%f",PH_DBG_ObjectTrackName(),Position().x,Position().y,Position().z); } BOOL ret =CScriptBinder::net_Spawn(DC); #else return (CScriptBinder::net_Spawn(DC)); #endif #ifdef DEBUG if(ph_dbg_draw_mask1.test(ph_m1_DbgTrackObject)&&stricmp(PH_DBG_ObjectTrackName(),*cName())==0) { Msg("CGameObject::net_Spawn obj %s Before CScriptBinder::net_Spawn %f,%f,%f",PH_DBG_ObjectTrackName(),Position().x,Position().y,Position().z); } return ret; #endif }
IC bool check_scale(const Fmatrix &m) { float det = DET(m); return (0.8f<det&&det<1.3f); }
int main() { int A[] = {1, 2, 4, 5, 1, 0, 0, 2, 3, 4, 2, 7, -1, -4, 0, 5}; printf("%d",DET(A, 4)); return 0; }
static int __devinit myri_sbus_probe(struct of_device *op, const struct of_device_id *match) { struct device_node *dp = op->node; static unsigned version_printed; struct net_device *dev; struct myri_eth *mp; const void *prop; static int num; int i, len; DET(("myri_ether_init(%p,%d):\n", op, num)); dev = alloc_etherdev(sizeof(struct myri_eth)); if (!dev) return -ENOMEM; if (version_printed++ == 0) printk(version); SET_NETDEV_DEV(dev, &op->dev); mp = netdev_priv(dev); spin_lock_init(&mp->irq_lock); mp->myri_op = op; for (i = 0; i < (RX_RING_SIZE + 1); i++) mp->rx_skbs[i] = NULL; for (i = 0; i < TX_RING_SIZE; i++) mp->tx_skbs[i] = NULL; prop = of_get_property(dp, "myrinet-eeprom-info", &len); if (prop) memcpy(&mp->eeprom, prop, sizeof(struct myri_eeprom)); if (!prop) { DET(("No EEPROM: ")); mp->eeprom.bus_type = BUS_TYPE_SBUS; mp->eeprom.cpuvers = of_getintprop_default(dp, "cpu_version", 0); mp->eeprom.cval = of_getintprop_default(dp, "clock_value", 0); mp->eeprom.ramsz = of_getintprop_default(dp, "sram_size", 0); if (!mp->eeprom.cpuvers) mp->eeprom.cpuvers = CPUVERS_2_3; if (mp->eeprom.cpuvers < CPUVERS_3_0) mp->eeprom.cval = 0; if (!mp->eeprom.ramsz) mp->eeprom.ramsz = (128 * 1024); prop = of_get_property(dp, "myrinet-board-id", &len); if (prop) memcpy(&mp->eeprom.id[0], prop, 6); else set_boardid_from_idprom(mp, num); prop = of_get_property(dp, "fpga_version", &len); if (prop) memcpy(&mp->eeprom.fvers[0], prop, 32); else memset(&mp->eeprom.fvers[0], 0, 32); if (mp->eeprom.cpuvers == CPUVERS_4_1) { if (mp->eeprom.ramsz == (128 * 1024)) mp->eeprom.ramsz = (256 * 1024); if ((mp->eeprom.cval == 0x40414041) || (mp->eeprom.cval == 0x90449044)) mp->eeprom.cval = 0x50e450e4; } } #ifdef DEBUG_DETECT dump_eeprom(mp); #endif for (i = 0; i < 6; i++) dev->dev_addr[i] = mp->eeprom.id[i]; determine_reg_space_size(mp); if (mp->eeprom.cpuvers < CPUVERS_4_0) { DET(("Mapping regs for cpuvers < CPUVERS_4_0\n")); mp->regs = of_ioremap(&op->resource[0], 0, mp->reg_size, "MyriCOM Regs"); if (!mp->regs) { printk("MyriCOM: Cannot map MyriCOM registers.\n"); goto err; } mp->lanai = mp->regs + (256 * 1024); mp->lregs = mp->lanai + (0x10000 * 2); } else { DET(("Mapping regs for cpuvers >= CPUVERS_4_0\n")); mp->cregs = of_ioremap(&op->resource[0], 0, PAGE_SIZE, "MyriCOM Control Regs"); mp->lregs = of_ioremap(&op->resource[0], (256 * 1024), PAGE_SIZE, "MyriCOM LANAI Regs"); mp->lanai = of_ioremap(&op->resource[0], (512 * 1024), mp->eeprom.ramsz, "MyriCOM SRAM"); } DET(("Registers mapped: cregs[%p] lregs[%p] lanai[%p]\n", mp->cregs, mp->lregs, mp->lanai)); if (mp->eeprom.cpuvers >= CPUVERS_4_0) mp->shmem_base = 0xf000; else mp->shmem_base = 0x8000; DET(("Shared memory base is %04x, ", mp->shmem_base)); mp->shmem = (struct myri_shmem __iomem *) (mp->lanai + (mp->shmem_base * 2)); DET(("shmem mapped at %p\n", mp->shmem)); mp->rqack = &mp->shmem->channel.recvqa; mp->rq = &mp->shmem->channel.recvq; mp->sq = &mp->shmem->channel.sendq; DET(("Resetting LANAI\n")); myri_reset_off(mp->lregs, mp->cregs); myri_reset_on(mp->cregs); myri_disable_irq(mp->lregs, mp->cregs); myri_reset_on(mp->cregs); mp->myri_bursts = of_getintprop_default(dp->parent, "burst-sizes", 0x00); if (!sbus_can_burst64()) mp->myri_bursts &= ~(DMA_BURST64); DET(("MYRI bursts %02x\n", mp->myri_bursts)); i = of_getintprop_default(dp, "interrupts", 0); if (i == 0) i = 4; DET(("prom_getint(interrupts)==%d, irqlvl set to %04x\n", i, (1 << i))); sbus_writel((1 << i), mp->cregs + MYRICTRL_IRQLVL); mp->dev = dev; dev->watchdog_timeo = 5*HZ; dev->irq = op->irqs[0]; dev->netdev_ops = &myri_ops; DET(("Requesting MYRIcom IRQ line.\n")); if (request_irq(dev->irq, &myri_interrupt, IRQF_SHARED, "MyriCOM Ethernet", (void *) dev)) { printk("MyriCOM: Cannot register interrupt handler.\n"); goto err; } dev->mtu = MYRINET_MTU; dev->header_ops = &myri_header_ops; dev->hard_header_len = (ETH_HLEN + MYRI_PAD_LEN); DET(("Loading LANAI firmware\n")); if (myri_load_lanai(mp)) { printk(KERN_ERR "MyriCOM: Cannot Load LANAI firmware.\n"); goto err_free_irq; } if (register_netdev(dev)) { printk("MyriCOM: Cannot register device.\n"); goto err_free_irq; } dev_set_drvdata(&op->dev, mp); num++; printk("%s: MyriCOM MyriNET Ethernet %pM\n", dev->name, dev->dev_addr); return 0; err_free_irq: free_irq(dev->irq, dev); err: free_netdev(dev); return -ENODEV; }