static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run) { u64 uninitialized_var(gpr); if (run->mmio.len > sizeof(gpr)) { printk(KERN_ERR "bad MMIO length: %d\n", run->mmio.len); return; } if (!vcpu->arch.mmio_host_swabbed) { switch (run->mmio.len) { case 8: gpr = *(u64 *)run->mmio.data; break; case 4: gpr = *(u32 *)run->mmio.data; break; case 2: gpr = *(u16 *)run->mmio.data; break; case 1: gpr = *(u8 *)run->mmio.data; break; } } else { switch (run->mmio.len) { case 8: gpr = swab64(*(u64 *)run->mmio.data); break; case 4: gpr = swab32(*(u32 *)run->mmio.data); break; case 2: gpr = swab16(*(u16 *)run->mmio.data); break; case 1: gpr = *(u8 *)run->mmio.data; break; } } if (vcpu->arch.mmio_sign_extend) { switch (run->mmio.len) { #ifdef CONFIG_PPC64 case 4: gpr = (s64)(s32)gpr; break; #endif case 2: gpr = (s64)(s16)gpr; break; case 1: gpr = (s64)(s8)gpr; break; } } kvmppc_set_gpr(vcpu, vcpu->arch.io_gpr, gpr); switch (vcpu->arch.io_gpr & KVM_MMIO_REG_EXT_MASK) { case KVM_MMIO_REG_GPR: kvmppc_set_gpr(vcpu, vcpu->arch.io_gpr, gpr); break; case KVM_MMIO_REG_FPR: VCPU_FPR(vcpu, vcpu->arch.io_gpr & KVM_MMIO_REG_MASK) = gpr; break; #ifdef CONFIG_PPC_BOOK3S case KVM_MMIO_REG_QPR: vcpu->arch.qpr[vcpu->arch.io_gpr & KVM_MMIO_REG_MASK] = gpr; break; case KVM_MMIO_REG_FQPR: VCPU_FPR(vcpu, vcpu->arch.io_gpr & KVM_MMIO_REG_MASK) = gpr; vcpu->arch.qpr[vcpu->arch.io_gpr & KVM_MMIO_REG_MASK] = gpr; break; #endif default: BUG(); } }
/* * The RSK board has the SMSC89218 wired up 'incorrectly'. * Byte-swapping is necessary, and so poor performance is inevitable. * This problem cannot evade by the swap function of CHIP, this can * evade by software Byte-swapping. * And this has problem by FIFO access only. pkt_data_pull/pkt_data_push * functions necessary to solve this problem. */ u32 pkt_data_pull(struct eth_device *dev, u32 addr) { volatile u16 *addr_16 = (u16 *)(dev->iobase + addr); return (u32)((swab16(*addr_16) << 16) & 0xFFFF0000)\ | swab16(*(addr_16 + 1)); }
static int ad7291_i2c_write(struct ad7291_chip_info *chip, u8 reg, u16 data) { return i2c_smbus_write_word_data(chip->client, reg, swab16(data)); }
static void jit_bundle_gen(struct pt_regs *regs, tilegx_bundle_bits bundle, int align_ctl) { struct thread_info *info = current_thread_info(); struct unaligned_jit_fragment frag; struct unaligned_jit_fragment *jit_code_area; tilegx_bundle_bits bundle_2 = 0; /* If bundle_2_enable = false, bundle_2 is fnop/nop operation. */ bool bundle_2_enable = true; uint64_t ra = -1, rb = -1, rd = -1, clob1 = -1, clob2 = -1, clob3 = -1; /* * Indicate if the unalign access * instruction's registers hit with * others in the same bundle. */ bool alias = false; bool load_n_store = true; bool load_store_signed = false; unsigned int load_store_size = 8; bool y1_br = false; /* True, for a branch in same bundle at Y1.*/ int y1_br_reg = 0; /* True for link operation. i.e. jalr or lnk at Y1 */ bool y1_lr = false; int y1_lr_reg = 0; bool x1_add = false;/* True, for load/store ADD instruction at X1*/ int x1_add_imm8 = 0; bool unexpected = false; int n = 0, k; jit_code_area = (struct unaligned_jit_fragment *)(info->unalign_jit_base); memset((void *)&frag, 0, sizeof(frag)); /* 0: X mode, Otherwise: Y mode. */ if (bundle & TILEGX_BUNDLE_MODE_MASK) { unsigned int mod, opcode; if (get_Opcode_Y1(bundle) == RRR_1_OPCODE_Y1 && get_RRROpcodeExtension_Y1(bundle) == UNARY_RRR_1_OPCODE_Y1) { opcode = get_UnaryOpcodeExtension_Y1(bundle); /* * Test "jalr", "jalrp", "jr", "jrp" instruction at Y1 * pipeline. */ switch (opcode) { case JALR_UNARY_OPCODE_Y1: case JALRP_UNARY_OPCODE_Y1: y1_lr = true; y1_lr_reg = 55; /* Link register. */ /* FALLTHROUGH */ case JR_UNARY_OPCODE_Y1: case JRP_UNARY_OPCODE_Y1: y1_br = true; y1_br_reg = get_SrcA_Y1(bundle); break; case LNK_UNARY_OPCODE_Y1: /* "lnk" at Y1 pipeline. */ y1_lr = true; y1_lr_reg = get_Dest_Y1(bundle); break; } } opcode = get_Opcode_Y2(bundle); mod = get_Mode(bundle); /* * bundle_2 is bundle after making Y2 as a dummy operation * - ld zero, sp */ bundle_2 = (bundle & (~GX_INSN_Y2_MASK)) | jit_y2_dummy(); /* Make Y1 as fnop if Y1 is a branch or lnk operation. */ if (y1_br || y1_lr) { bundle_2 &= ~(GX_INSN_Y1_MASK); bundle_2 |= jit_y1_fnop(); } if (is_y0_y1_nop(bundle_2)) bundle_2_enable = false; if (mod == MODE_OPCODE_YC2) { /* Store. */ load_n_store = false; load_store_size = 1 << opcode; load_store_signed = false; find_regs(bundle, 0, &ra, &rb, &clob1, &clob2, &clob3, &alias); if (load_store_size > 8) unexpected = true; } else { /* Load. */ load_n_store = true; if (mod == MODE_OPCODE_YB2) { switch (opcode) { case LD_OPCODE_Y2: load_store_signed = false; load_store_size = 8; break; case LD4S_OPCODE_Y2: load_store_signed = true; load_store_size = 4; break; case LD4U_OPCODE_Y2: load_store_signed = false; load_store_size = 4; break; default: unexpected = true; } } else if (mod == MODE_OPCODE_YA2) { if (opcode == LD2S_OPCODE_Y2) { load_store_signed = true; load_store_size = 2; } else if (opcode == LD2U_OPCODE_Y2) { load_store_signed = false; load_store_size = 2; } else unexpected = true; } else unexpected = true; find_regs(bundle, &rd, &ra, &rb, &clob1, &clob2, &clob3, &alias); } } else { unsigned int opcode; /* bundle_2 is bundle after making X1 as "fnop". */ bundle_2 = (bundle & (~GX_INSN_X1_MASK)) | jit_x1_fnop(); if (is_x0_x1_nop(bundle_2)) bundle_2_enable = false; if (get_Opcode_X1(bundle) == RRR_0_OPCODE_X1) { opcode = get_UnaryOpcodeExtension_X1(bundle); if (get_RRROpcodeExtension_X1(bundle) == UNARY_RRR_0_OPCODE_X1) { load_n_store = true; find_regs(bundle, &rd, &ra, &rb, &clob1, &clob2, &clob3, &alias); switch (opcode) { case LD_UNARY_OPCODE_X1: load_store_signed = false; load_store_size = 8; break; case LD4S_UNARY_OPCODE_X1: load_store_signed = true; /* FALLTHROUGH */ case LD4U_UNARY_OPCODE_X1: load_store_size = 4; break; case LD2S_UNARY_OPCODE_X1: load_store_signed = true; /* FALLTHROUGH */ case LD2U_UNARY_OPCODE_X1: load_store_size = 2; break; default: unexpected = true; } } else { load_n_store = false; load_store_signed = false; find_regs(bundle, 0, &ra, &rb, &clob1, &clob2, &clob3, &alias); opcode = get_RRROpcodeExtension_X1(bundle); switch (opcode) { case ST_RRR_0_OPCODE_X1: load_store_size = 8; break; case ST4_RRR_0_OPCODE_X1: load_store_size = 4; break; case ST2_RRR_0_OPCODE_X1: load_store_size = 2; break; default: unexpected = true; } } } else if (get_Opcode_X1(bundle) == IMM8_OPCODE_X1) { load_n_store = true; opcode = get_Imm8OpcodeExtension_X1(bundle); switch (opcode) { case LD_ADD_IMM8_OPCODE_X1: load_store_size = 8; break; case LD4S_ADD_IMM8_OPCODE_X1: load_store_signed = true; /* FALLTHROUGH */ case LD4U_ADD_IMM8_OPCODE_X1: load_store_size = 4; break; case LD2S_ADD_IMM8_OPCODE_X1: load_store_signed = true; /* FALLTHROUGH */ case LD2U_ADD_IMM8_OPCODE_X1: load_store_size = 2; break; case ST_ADD_IMM8_OPCODE_X1: load_n_store = false; load_store_size = 8; break; case ST4_ADD_IMM8_OPCODE_X1: load_n_store = false; load_store_size = 4; break; case ST2_ADD_IMM8_OPCODE_X1: load_n_store = false; load_store_size = 2; break; default: unexpected = true; } if (!unexpected) { x1_add = true; if (load_n_store) x1_add_imm8 = get_Imm8_X1(bundle); else x1_add_imm8 = get_Dest_Imm8_X1(bundle); } find_regs(bundle, load_n_store ? (&rd) : NULL, &ra, &rb, &clob1, &clob2, &clob3, &alias); } else unexpected = true; } /* * Some sanity check for register numbers extracted from fault bundle. */ if (check_regs(rd, ra, rb, clob1, clob2, clob3) == true) unexpected = true; /* Give warning if register ra has an aligned address. */ if (!unexpected) WARN_ON(!((load_store_size - 1) & (regs->regs[ra]))); /* * Fault came from kernel space, here we only need take care of * unaligned "get_user/put_user" macros defined in "uaccess.h". * Basically, we will handle bundle like this: * {ld/2u/4s rd, ra; movei rx, 0} or {st/2/4 ra, rb; movei rx, 0} * (Refer to file "arch/tile/include/asm/uaccess.h" for details). * For either load or store, byte-wise operation is performed by calling * get_user() or put_user(). If the macro returns non-zero value, * set the value to rx, otherwise set zero to rx. Finally make pc point * to next bundle and return. */ if (EX1_PL(regs->ex1) != USER_PL) { unsigned long rx = 0; unsigned long x = 0, ret = 0; if (y1_br || y1_lr || x1_add || (load_store_signed != (load_n_store && load_store_size == 4))) { /* No branch, link, wrong sign-ext or load/store add. */ unexpected = true; } else if (!unexpected) { if (bundle & TILEGX_BUNDLE_MODE_MASK) { /* * Fault bundle is Y mode. * Check if the Y1 and Y0 is the form of * { movei rx, 0; nop/fnop }, if yes, * find the rx. */ if ((get_Opcode_Y1(bundle) == ADDI_OPCODE_Y1) && (get_SrcA_Y1(bundle) == TREG_ZERO) && (get_Imm8_Y1(bundle) == 0) && is_bundle_y0_nop(bundle)) { rx = get_Dest_Y1(bundle); } else if ((get_Opcode_Y0(bundle) == ADDI_OPCODE_Y0) && (get_SrcA_Y0(bundle) == TREG_ZERO) && (get_Imm8_Y0(bundle) == 0) && is_bundle_y1_nop(bundle)) { rx = get_Dest_Y0(bundle); } else { unexpected = true; } } else { /* * Fault bundle is X mode. * Check if the X0 is 'movei rx, 0', * if yes, find the rx. */ if ((get_Opcode_X0(bundle) == IMM8_OPCODE_X0) && (get_Imm8OpcodeExtension_X0(bundle) == ADDI_IMM8_OPCODE_X0) && (get_SrcA_X0(bundle) == TREG_ZERO) && (get_Imm8_X0(bundle) == 0)) { rx = get_Dest_X0(bundle); } else { unexpected = true; } } /* rx should be less than 56. */ if (!unexpected && (rx >= 56)) unexpected = true; } if (!search_exception_tables(regs->pc)) { /* No fixup in the exception tables for the pc. */ unexpected = true; } if (unexpected) { /* Unexpected unalign kernel fault. */ struct task_struct *tsk = validate_current(); bust_spinlocks(1); show_regs(regs); if (unlikely(tsk->pid < 2)) { panic("Kernel unalign fault running %s!", tsk->pid ? "init" : "the idle task"); } #ifdef SUPPORT_DIE die("Oops", regs); #endif bust_spinlocks(1); do_group_exit(SIGKILL); } else { unsigned long i, b = 0; unsigned char *ptr = (unsigned char *)regs->regs[ra]; if (load_n_store) { /* handle get_user(x, ptr) */ for (i = 0; i < load_store_size; i++) { ret = get_user(b, ptr++); if (!ret) { /* Success! update x. */ #ifdef __LITTLE_ENDIAN x |= (b << (8 * i)); #else x <<= 8; x |= b; #endif /* __LITTLE_ENDIAN */ } else { x = 0; break; } } /* Sign-extend 4-byte loads. */ if (load_store_size == 4) x = (long)(int)x; /* Set register rd. */ regs->regs[rd] = x; /* Set register rx. */ regs->regs[rx] = ret; /* Bump pc. */ regs->pc += 8; } else { /* Handle put_user(x, ptr) */ x = regs->regs[rb]; #ifdef __LITTLE_ENDIAN b = x; #else /* * Swap x in order to store x from low * to high memory same as the * little-endian case. */ switch (load_store_size) { case 8: b = swab64(x); break; case 4: b = swab32(x); break; case 2: b = swab16(x); break; } #endif /* __LITTLE_ENDIAN */ for (i = 0; i < load_store_size; i++) { ret = put_user(b, ptr++); if (ret) break; /* Success! shift 1 byte. */ b >>= 8; } /* Set register rx. */ regs->regs[rx] = ret; /* Bump pc. */ regs->pc += 8; } } unaligned_fixup_count++; if (unaligned_printk) { pr_info("%s/%d - Unalign fixup for kernel access to userspace %lx\n", current->comm, current->pid, regs->regs[ra]); } /* Done! Return to the exception handler. */ return; }
static void sun3_82586_rcv_int(struct net_device *dev) { int status,cnt=0; unsigned short totlen; struct sk_buff *skb; struct rbd_struct *rbd; struct priv *p = (struct priv *) dev->priv; if(debuglevel > 0) printk("R"); for(;(status = p->rfd_top->stat_high) & RFD_COMPL;) { rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset); if(status & RFD_OK) /* frame received without error? */ { if( (totlen = swab16(rbd->status)) & RBD_LAST) /* the first and the last buffer? */ { totlen &= RBD_MASK; /* length of this frame */ rbd->status = 0; skb = (struct sk_buff *) dev_alloc_skb(totlen+2); if(skb != NULL) { skb_reserve(skb,2); skb_put(skb,totlen); skb_copy_to_linear_data(skb,(char *) p->base+swab32((unsigned long) rbd->buffer),totlen); skb->protocol=eth_type_trans(skb,dev); netif_rx(skb); p->stats.rx_packets++; } else p->stats.rx_dropped++; } else { int rstat; /* free all RBD's until RBD_LAST is set */ totlen = 0; while(!((rstat=swab16(rbd->status)) & RBD_LAST)) { totlen += rstat & RBD_MASK; if(!rstat) { printk("%s: Whoops .. no end mark in RBD list\n",dev->name); break; } rbd->status = 0; rbd = (struct rbd_struct *) make32(rbd->next); } totlen += rstat & RBD_MASK; rbd->status = 0; printk("%s: received oversized frame! length: %d\n",dev->name,totlen); p->stats.rx_dropped++; } } else /* frame !(ok), only with 'save-bad-frames' */ { printk("%s: oops! rfd-error-status: %04x\n",dev->name,status); p->stats.rx_errors++; } p->rfd_top->stat_high = 0; p->rfd_top->last = RFD_SUSP; /* maybe exchange by RFD_LAST */ p->rfd_top->rbd_offset = 0xffff; p->rfd_last->last = 0; /* delete RFD_SUSP */ p->rfd_last = p->rfd_top; p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */ p->scb->rfa_offset = make16(p->rfd_top); if(debuglevel > 0) printk("%d",cnt++); } if(automatic_resume) { WAIT_4_SCB_CMD(); p->scb->cmd_ruc = RUC_RESUME; sun3_attn586(); WAIT_4_SCB_CMD_RUC(); } #ifdef WAIT_4_BUSY { int i; for(i=0;i<1024;i++) { if(p->rfd_top->status) break; DELAY_16(); if(i == 1023) printk("%s: RU hasn't fetched next RFD (not busy/complete)\n",dev->name); } } #endif #if 0 if(!at_least_one) { int i; volatile struct rfd_struct *rfds=p->rfd_top; volatile struct rbd_struct *rbds; printk("%s: received a FC intr. without having a frame: %04x %d\n",dev->name,status,old_at_least); for(i=0;i< (p->num_recv_buffs+4);i++) { rbds = (struct rbd_struct *) make32(rfds->rbd_offset); printk("%04x:%04x ",rfds->status,rbds->status); rfds = (struct rfd_struct *) make32(rfds->next); } printk("\nerrs: %04x %04x stat: %04x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->status); printk("\nerrs: %04x %04x rus: %02x, cus: %02x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->rus,(int)p->scb->cus); } old_at_least = at_least_one; #endif if(debuglevel > 0) printk("r"); }
static inline void writereg(struct net_device *dev, int portno, int value) { nubus_writew(swab16(value), dev->mem_start + portno); }
/* The typical workload of the driver: Handle the network interface interrupts. */ static irqreturn_t net_interrupt(int irq, void *dev_id) { struct net_device *dev = dev_id; struct net_local *lp; int ioaddr, status; if (dev == NULL) { printk ("net_interrupt(): irq %d for unknown device.\n", irq); return IRQ_NONE; } ioaddr = dev->base_addr; lp = netdev_priv(dev); /* we MUST read all the events out of the ISQ, otherwise we'll never get interrupted again. As a consequence, we can't have any limit on the number of times we loop in the interrupt handler. The hardware guarantees that eventually we'll run out of events. Of course, if you're on a slow machine, and packets are arriving faster than you can read them off, you're screwed. Hasta la vista, baby! */ while ((status = swab16(nubus_readw(dev->base_addr + ISQ_PORT)))) { if (net_debug > 4)printk("%s: event=%04x\n", dev->name, status); switch(status & ISQ_EVENT_MASK) { case ISQ_RECEIVER_EVENT: /* Got a packet(s). */ net_rx(dev); break; case ISQ_TRANSMITTER_EVENT: dev->stats.tx_packets++; netif_wake_queue(dev); if ((status & TX_OK) == 0) dev->stats.tx_errors++; if (status & TX_LOST_CRS) dev->stats.tx_carrier_errors++; if (status & TX_SQE_ERROR) dev->stats.tx_heartbeat_errors++; if (status & TX_LATE_COL) dev->stats.tx_window_errors++; if (status & TX_16_COL) dev->stats.tx_aborted_errors++; break; case ISQ_BUFFER_EVENT: if (status & READY_FOR_TX) { /* we tried to transmit a packet earlier, but inexplicably ran out of buffers. That shouldn't happen since we only ever load one packet. Shrug. Do the right thing anyway. */ netif_wake_queue(dev); } if (status & TX_UNDERRUN) { if (net_debug > 0) printk("%s: transmit underrun\n", dev->name); lp->send_underrun++; if (lp->send_underrun == 3) lp->send_cmd = TX_AFTER_381; else if (lp->send_underrun == 6) lp->send_cmd = TX_AFTER_ALL; } break; case ISQ_RX_MISS_EVENT: dev->stats.rx_missed_errors += (status >> 6); break; case ISQ_TX_COL_EVENT: dev->stats.collisions += (status >> 6); break; } } return IRQ_HANDLED; }
/* Probe for the CS8900 card in slot E. We won't bother looking anywhere else until we have a really good reason to do so. */ int __init mac89x0_probe(struct net_device *dev) { static int once_is_enough; struct net_local *lp; static unsigned version_printed; int i, slot; unsigned rev_type = 0; unsigned long ioaddr; unsigned short sig; SET_MODULE_OWNER(dev); if (once_is_enough) return -ENODEV; once_is_enough = 1; /* We might have to parameterize this later */ slot = 0xE; /* Get out now if there's a real NuBus card in slot E */ if (nubus_find_slot(slot, NULL) != NULL) return -ENODEV; /* The pseudo-ISA bits always live at offset 0x300 (gee, wonder why...) */ ioaddr = (unsigned long) nubus_slot_addr(slot) | (((slot&0xf) << 20) + DEFAULTIOBASE); { unsigned long flags; int card_present; local_irq_save(flags); card_present = hwreg_present((void*) ioaddr+4) && hwreg_present((void*) ioaddr + DATA_PORT); local_irq_restore(flags); if (!card_present) return -ENODEV; } nubus_writew(0, ioaddr + ADD_PORT); sig = nubus_readw(ioaddr + DATA_PORT); if (sig != swab16(CHIP_EISA_ID_SIG)) return -ENODEV; /* Initialize the net_device structure. */ if (dev->priv == NULL) { dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL); if (!dev->priv) return -ENOMEM; memset(dev->priv, 0, sizeof(struct net_local)); } lp = (struct net_local *)dev->priv; /* Fill in the 'dev' fields. */ dev->base_addr = ioaddr; dev->mem_start = (unsigned long) nubus_slot_addr(slot) | (((slot&0xf) << 20) + MMIOBASE); dev->mem_end = dev->mem_start + 0x1000; /* Turn on shared memory */ writereg_io(dev, PP_BusCTL, MEMORY_ON); /* get the chip type */ rev_type = readreg(dev, PRODUCT_ID_ADD); lp->chip_type = rev_type &~ REVISON_BITS; lp->chip_revision = ((rev_type & REVISON_BITS) >> 8) + 'A'; /* Check the chip type and revision in order to set the correct send command CS8920 revision C and CS8900 revision F can use the faster send. */ lp->send_cmd = TX_AFTER_381; if (lp->chip_type == CS8900 && lp->chip_revision >= 'F') lp->send_cmd = TX_NOW; if (lp->chip_type != CS8900 && lp->chip_revision >= 'C') lp->send_cmd = TX_NOW; if (net_debug && version_printed++ == 0) printk(version); printk(KERN_INFO "%s: cs89%c0%s rev %c found at %#8lx", dev->name, lp->chip_type==CS8900?'0':'2', lp->chip_type==CS8920M?"M":"", lp->chip_revision, dev->base_addr); /* Try to read the MAC address */ if ((readreg(dev, PP_SelfST) & (EEPROM_PRESENT | EEPROM_OK)) == 0) { printk("\nmac89x0: No EEPROM, giving up now.\n"); kfree(dev->priv); dev->priv = NULL; return -ENODEV; } else { for (i = 0; i < ETH_ALEN; i += 2) { /* Big-endian (why??!) */ unsigned short s = readreg(dev, PP_IA + i); dev->dev_addr[i] = s >> 8; dev->dev_addr[i+1] = s & 0xff; } } dev->irq = SLOT2IRQ(slot); printk(" IRQ %d ADDR ", dev->irq); /* print the ethernet address. */ for (i = 0; i < ETH_ALEN; i++) printk("%2.2x%s", dev->dev_addr[i], ((i < ETH_ALEN-1) ? ":" : "")); dev->open = net_open; dev->stop = net_close; dev->hard_start_xmit = net_send_packet; dev->get_stats = net_get_stats; dev->set_multicast_list = &set_multicast_list; dev->set_mac_address = &set_mac_address; /* Fill in the fields of the net_device structure with ethernet values. */ ether_setup(dev); printk("\n"); return 0; }
static int jc42_write_value(struct i2c_client *client, u8 reg, u16 value) { return i2c_smbus_write_word_data(client, reg, swab16(value)); }
static int write_reg(struct i2c_client *client, int reg, int value) { i2c_smbus_write_word_data(client, reg, swab16(value)); return 0; }
struct super_block * ext2_read_super (struct super_block * sb, void * data, int silent) { struct buffer_head * bh; struct ext2_super_block * es; unsigned long sb_block = 1; unsigned short resuid = EXT2_DEF_RESUID; unsigned short resgid = EXT2_DEF_RESGID; unsigned long logic_sb_block = 1; kdev_t dev = sb->s_dev; int db_count; int i, j; sb->u.ext2_sb.s_mount_opt = 0; set_opt (sb->u.ext2_sb.s_mount_opt, CHECK_NORMAL); if (!parse_options ((char *) data, &sb_block, &resuid, &resgid, &sb->u.ext2_sb.s_mount_opt)) { sb->s_dev = 0; return NULL; } MOD_INC_USE_COUNT; lock_super (sb); set_blocksize (dev, BLOCK_SIZE); if (!(bh = bread (dev, sb_block, BLOCK_SIZE))) { sb->s_dev = 0; unlock_super (sb); printk ("EXT2-fs: unable to read superblock\n"); MOD_DEC_USE_COUNT; return NULL; } /* * Note: s_es must be initialized s_es as soon as possible because * some ext2 macro-instructions depend on its value */ es = (struct ext2_super_block *) bh->b_data; sb->u.ext2_sb.s_es = es; sb->s_magic = swab16(es->s_magic); if (sb->s_magic != EXT2_SUPER_MAGIC) { if (!silent) printk ("VFS: Can't find an ext2 filesystem on dev " "%s.\n", kdevname(dev)); failed_mount: sb->s_dev = 0; unlock_super (sb); if (bh) brelse(bh); MOD_DEC_USE_COUNT; return NULL; } if (swab32(es->s_rev_level) > EXT2_GOOD_OLD_REV) { if (swab32(es->s_feature_incompat) & ~EXT2_FEATURE_INCOMPAT_SUPP) { printk("EXT2-fs: %s: couldn't mount because of " "unsupported optional features.\n", kdevname(dev)); goto failed_mount; } if (!(sb->s_flags & MS_RDONLY) && (swab32(es->s_feature_ro_compat) & ~EXT2_FEATURE_RO_COMPAT_SUPP)) { printk("EXT2-fs: %s: couldn't mount RDWR because of " "unsupported optional features.\n", kdevname(dev)); goto failed_mount; } } sb->s_blocksize_bits = swab32(sb->u.ext2_sb.s_es->s_log_block_size) + 10; sb->s_blocksize = 1 << sb->s_blocksize_bits; if (sb->s_blocksize != BLOCK_SIZE && (sb->s_blocksize == 1024 || sb->s_blocksize == 2048 || sb->s_blocksize == 4096)) { unsigned long offset; brelse (bh); set_blocksize (dev, sb->s_blocksize); logic_sb_block = (sb_block*BLOCK_SIZE) / sb->s_blocksize; offset = (sb_block*BLOCK_SIZE) % sb->s_blocksize; bh = bread (dev, logic_sb_block, sb->s_blocksize); if(!bh) { printk("EXT2-fs: Couldn't read superblock on " "2nd try.\n"); goto failed_mount; } es = (struct ext2_super_block *) (((char *)bh->b_data) + offset); sb->u.ext2_sb.s_es = es; if (es->s_magic != swab16(EXT2_SUPER_MAGIC)) { printk ("EXT2-fs: Magic mismatch, very weird !\n"); goto failed_mount; } } if (swab32(es->s_rev_level) == EXT2_GOOD_OLD_REV) { sb->u.ext2_sb.s_inode_size = EXT2_GOOD_OLD_INODE_SIZE; sb->u.ext2_sb.s_first_ino = EXT2_GOOD_OLD_FIRST_INO; } else { sb->u.ext2_sb.s_inode_size = swab16(es->s_inode_size); sb->u.ext2_sb.s_first_ino = swab32(es->s_first_ino); if (sb->u.ext2_sb.s_inode_size != EXT2_GOOD_OLD_INODE_SIZE) { printk ("EXT2-fs: unsupported inode size: %d\n", sb->u.ext2_sb.s_inode_size); goto failed_mount; } } sb->u.ext2_sb.s_frag_size = EXT2_MIN_FRAG_SIZE << (__s32) swab32(es->s_log_frag_size); if (sb->u.ext2_sb.s_frag_size) sb->u.ext2_sb.s_frags_per_block = sb->s_blocksize / sb->u.ext2_sb.s_frag_size; else sb->s_magic = 0; sb->u.ext2_sb.s_blocks_per_group = swab32(es->s_blocks_per_group); sb->u.ext2_sb.s_frags_per_group = swab32(es->s_frags_per_group); sb->u.ext2_sb.s_inodes_per_group = swab32(es->s_inodes_per_group); sb->u.ext2_sb.s_inodes_per_block = sb->s_blocksize / EXT2_INODE_SIZE(sb); sb->u.ext2_sb.s_itb_per_group = sb->u.ext2_sb.s_inodes_per_group / sb->u.ext2_sb.s_inodes_per_block; sb->u.ext2_sb.s_desc_per_block = sb->s_blocksize / sizeof (struct ext2_group_desc); sb->u.ext2_sb.s_sbh = bh; if (resuid != EXT2_DEF_RESUID) sb->u.ext2_sb.s_resuid = resuid; else sb->u.ext2_sb.s_resuid = swab16(es->s_def_resuid); if (resgid != EXT2_DEF_RESGID) sb->u.ext2_sb.s_resgid = resgid; else sb->u.ext2_sb.s_resgid = swab16(es->s_def_resgid); sb->u.ext2_sb.s_mount_state = swab16(es->s_state); sb->u.ext2_sb.s_rename_lock = 0; sb->u.ext2_sb.s_rename_wait = NULL; sb->u.ext2_sb.s_addr_per_block_bits = log2 (EXT2_ADDR_PER_BLOCK(sb)); sb->u.ext2_sb.s_desc_per_block_bits = log2 (EXT2_DESC_PER_BLOCK(sb)); if (sb->s_magic != EXT2_SUPER_MAGIC) { if (!silent) printk ("VFS: Can't find an ext2 filesystem on dev " "%s.\n", kdevname(dev)); goto failed_mount; } if (sb->s_blocksize != bh->b_size) { if (!silent) printk ("VFS: Unsupported blocksize on dev " "%s.\n", kdevname(dev)); goto failed_mount; } if (sb->s_blocksize != sb->u.ext2_sb.s_frag_size) { printk ("EXT2-fs: fragsize %lu != blocksize %lu (not supported yet)\n", sb->u.ext2_sb.s_frag_size, sb->s_blocksize); goto failed_mount; } if (sb->u.ext2_sb.s_blocks_per_group > sb->s_blocksize * 8) { printk ("EXT2-fs: #blocks per group too big: %lu\n", sb->u.ext2_sb.s_blocks_per_group); goto failed_mount; } if (sb->u.ext2_sb.s_frags_per_group > sb->s_blocksize * 8) { printk ("EXT2-fs: #fragments per group too big: %lu\n", sb->u.ext2_sb.s_frags_per_group); goto failed_mount; } if (sb->u.ext2_sb.s_inodes_per_group > sb->s_blocksize * 8) { printk ("EXT2-fs: #inodes per group too big: %lu\n", sb->u.ext2_sb.s_inodes_per_group); goto failed_mount; } sb->u.ext2_sb.s_groups_count = (swab32(es->s_blocks_count) - swab32(es->s_first_data_block) + EXT2_BLOCKS_PER_GROUP(sb) - 1) / EXT2_BLOCKS_PER_GROUP(sb); db_count = (sb->u.ext2_sb.s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) / EXT2_DESC_PER_BLOCK(sb); sb->u.ext2_sb.s_group_desc = kmalloc (db_count * sizeof (struct buffer_head *), GFP_KERNEL); if (sb->u.ext2_sb.s_group_desc == NULL) { printk ("EXT2-fs: not enough memory\n"); goto failed_mount; } for (i = 0; i < db_count; i++) { sb->u.ext2_sb.s_group_desc[i] = bread (dev, logic_sb_block + i + 1, sb->s_blocksize); if (!sb->u.ext2_sb.s_group_desc[i]) { for (j = 0; j < i; j++) brelse (sb->u.ext2_sb.s_group_desc[j]); kfree_s (sb->u.ext2_sb.s_group_desc, db_count * sizeof (struct buffer_head *)); printk ("EXT2-fs: unable to read group descriptors\n"); goto failed_mount; } } if (!ext2_check_descriptors (sb)) { for (j = 0; j < db_count; j++) brelse (sb->u.ext2_sb.s_group_desc[j]); kfree_s (sb->u.ext2_sb.s_group_desc, db_count * sizeof (struct buffer_head *)); printk ("EXT2-fs: group descriptors corrupted !\n"); goto failed_mount; } for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) { sb->u.ext2_sb.s_inode_bitmap_number[i] = 0; sb->u.ext2_sb.s_inode_bitmap[i] = NULL; sb->u.ext2_sb.s_block_bitmap_number[i] = 0; sb->u.ext2_sb.s_block_bitmap[i] = NULL; } sb->u.ext2_sb.s_loaded_inode_bitmaps = 0; sb->u.ext2_sb.s_loaded_block_bitmaps = 0; sb->u.ext2_sb.s_db_per_group = db_count; unlock_super (sb); /* * set up enough so that it can read an inode */ sb->s_dev = dev; sb->s_op = &ext2_sops; if (!(sb->s_mounted = iget (sb, EXT2_ROOT_INO))) { sb->s_dev = 0; for (i = 0; i < db_count; i++) if (sb->u.ext2_sb.s_group_desc[i]) brelse (sb->u.ext2_sb.s_group_desc[i]); kfree_s (sb->u.ext2_sb.s_group_desc, db_count * sizeof (struct buffer_head *)); brelse (bh); printk ("EXT2-fs: get root inode failed\n"); MOD_DEC_USE_COUNT; return NULL; } ext2_setup_super (sb, es); return sb; }
static inline int tmp102_write_reg(struct i2c_client *client, u8 reg, u16 val) { return i2c_smbus_write_word_data(client, reg, swab16(val)); }
/* SMBus specifies low byte first, but the TMP102 returns high byte first, * so we have to swab16 the values */ static inline int tmp102_read_reg(struct i2c_client *client, u8 reg) { int result = i2c_smbus_read_word_data(client, reg); return result < 0 ? result : swab16(result); }
/* * Probes Micron sensors with 8 bit address and 16 bit register width */ static int em28xx_probe_sensor_micron(struct em28xx *dev) { int ret, i; char *name; u16 id; struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus]; dev->em28xx_sensor = EM28XX_NOSENSOR; for (i = 0; micron_sensor_addrs[i] != I2C_CLIENT_END; i++) { client->addr = micron_sensor_addrs[i]; /* Read chip ID from register 0x00 */ ret = i2c_smbus_read_word_data(client, 0x00); /* assumes LE */ if (ret < 0) { if (ret != -ENXIO) dev_err(&dev->intf->dev, "couldn't read from i2c device 0x%02x: error %i\n", client->addr << 1, ret); continue; } id = swab16(ret); /* LE -> BE */ /* Read chip ID from register 0xff */ ret = i2c_smbus_read_word_data(client, 0xff); if (ret < 0) { dev_err(&dev->intf->dev, "couldn't read from i2c device 0x%02x: error %i\n", client->addr << 1, ret); continue; } /* Validate chip ID to be sure we have a Micron device */ if (id != swab16(ret)) continue; /* Check chip ID */ switch (id) { case 0x1222: name = "MT9V012"; /* MI370 */ /* 640x480 */ break; case 0x1229: name = "MT9V112"; /* 640x480 */ break; case 0x1433: name = "MT9M011"; /* 1280x1024 */ break; case 0x143a: /* found in the ECS G200 */ name = "MT9M111"; /* MI1310 */ /* 1280x1024 */ dev->em28xx_sensor = EM28XX_MT9M111; break; case 0x148c: name = "MT9M112"; /* MI1320 */ /* 1280x1024 */ break; case 0x1511: name = "MT9D011"; /* MI2010 */ /* 1600x1200 */ break; case 0x8232: case 0x8243: /* rev B */ name = "MT9V011"; /* MI360 */ /* 640x480 */ dev->em28xx_sensor = EM28XX_MT9V011; break; case 0x8431: name = "MT9M001"; /* 1280x1024 */ dev->em28xx_sensor = EM28XX_MT9M001; break; default: dev_info(&dev->intf->dev, "unknown Micron sensor detected: 0x%04x\n", id); return 0; } if (dev->em28xx_sensor == EM28XX_NOSENSOR) dev_info(&dev->intf->dev, "unsupported sensor detected: %s\n", name); else dev_info(&dev->intf->dev, "sensor %s detected\n", name); return 0; } return -ENODEV; }
static inline void writereg_io(struct net_device *dev, int portno, int value) { nubus_writew(swab16(portno), dev->base_addr + ADD_PORT); nubus_writew(swab16(value), dev->base_addr + DATA_PORT); }
int main(int argc, char *argv[]) { int fd_vmlinux, fd_initrd, fd_outfile; FILHDR efile; AOUTHDR eaout; SCNHDR esecs[3]; struct stat st; char buf[1024]; unsigned long loadaddr; unsigned long initrd_header[2]; int i, cnt; int swab = 0; if (argc != 4) { printf("Usage: %s <vmlinux> <initrd> <outfile>\n", argv[0]); exit(1); } if ((fd_vmlinux = open (argv[1], O_RDONLY)) < 0) die("open vmlinux"); if (read (fd_vmlinux, &efile, sizeof efile) != sizeof efile) die("read file header"); if (read (fd_vmlinux, &eaout, sizeof eaout) != sizeof eaout) die("read aout header"); if (read (fd_vmlinux, esecs, sizeof esecs) != sizeof esecs) die("read section headers"); /* * check whether the file is good for us */ /* TBD */ /* * check, if we have to swab words */ if (ntohs(0xaa55) == 0xaa55) { if (efile.f_magic == swab16(MIPSELMAGIC)) swab = 1; } else { if (efile.f_magic == swab16(MIPSEBMAGIC)) swab = 1; } /* make sure we have an empty data segment for the initrd */ if (eaout.dsize || esecs[1].s_size) { fprintf(stderr, "Data segment not empty. Giving up!\n"); exit(1); } if ((fd_initrd = open (argv[2], O_RDONLY)) < 0) die("open initrd"); if (fstat (fd_initrd, &st) < 0) die("fstat initrd"); loadaddr = ((SWAB(esecs[2].s_vaddr) + SWAB(esecs[2].s_size) + MIPS_PAGE_SIZE-1) & ~MIPS_PAGE_MASK) - 8; if (loadaddr < (SWAB(esecs[2].s_vaddr) + SWAB(esecs[2].s_size))) loadaddr += MIPS_PAGE_SIZE; initrd_header[0] = SWAB(0x494E5244); initrd_header[1] = SWAB(st.st_size); eaout.dsize = esecs[1].s_size = initrd_header[1] = SWAB(st.st_size+8); eaout.data_start = esecs[1].s_vaddr = esecs[1].s_paddr = SWAB(loadaddr); if ((fd_outfile = open (argv[3], O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) die("open outfile"); if (write (fd_outfile, &efile, sizeof efile) != sizeof efile) die("write file header"); if (write (fd_outfile, &eaout, sizeof eaout) != sizeof eaout) die("write aout header"); if (write (fd_outfile, esecs, sizeof esecs) != sizeof esecs) die("write section headers"); /* skip padding */ if(lseek(fd_vmlinux, SWAB(esecs[0].s_scnptr), SEEK_SET) == (off_t)-1) die("lseek vmlinux"); if(lseek(fd_outfile, SWAB(esecs[0].s_scnptr), SEEK_SET) == (off_t)-1) die("lseek outfile"); /* copy text segment */ cnt = SWAB(eaout.tsize); while (cnt) { if ((i = read (fd_vmlinux, buf, sizeof buf)) <= 0) die("read vmlinux"); if (write (fd_outfile, buf, i) != i) die("write vmlinux"); cnt -= i; } if (write (fd_outfile, initrd_header, sizeof initrd_header) != sizeof initrd_header) die("write initrd header"); while ((i = read (fd_initrd, buf, sizeof buf)) > 0) if (write (fd_outfile, buf, i) != i) die("write initrd"); close(fd_vmlinux); close(fd_initrd); return 0; }
/* These are for reading/writing registers in shared memory */ static inline int readreg(struct net_device *dev, int portno) { return swab16(nubus_readw(dev->mem_start + portno)); }
/* All registers are word-sized. * AD7879 uses a high-byte first convention. */ static int ad7879_i2c_read(struct device *dev, u8 reg) { struct i2c_client *client = to_i2c_client(dev); return swab16(i2c_smbus_read_word_data(client, reg)); }
/* Probe for the CS8900 card in slot E. We won't bother looking anywhere else until we have a really good reason to do so. */ struct net_device * __init mac89x0_probe(int unit) { struct net_device *dev; static int once_is_enough; struct net_local *lp; static unsigned version_printed; int i, slot; unsigned rev_type = 0; unsigned long ioaddr; unsigned short sig; int err = -ENODEV; if (!MACH_IS_MAC) return ERR_PTR(-ENODEV); dev = alloc_etherdev(sizeof(struct net_local)); if (!dev) return ERR_PTR(-ENOMEM); if (unit >= 0) { sprintf(dev->name, "eth%d", unit); netdev_boot_setup_check(dev); } if (once_is_enough) goto out; once_is_enough = 1; /* We might have to parameterize this later */ slot = 0xE; /* Get out now if there's a real NuBus card in slot E */ if (nubus_find_slot(slot, NULL) != NULL) goto out; /* The pseudo-ISA bits always live at offset 0x300 (gee, wonder why...) */ ioaddr = (unsigned long) nubus_slot_addr(slot) | (((slot&0xf) << 20) + DEFAULTIOBASE); { unsigned long flags; int card_present; local_irq_save(flags); card_present = (hwreg_present((void*) ioaddr+4) && hwreg_present((void*) ioaddr + DATA_PORT)); local_irq_restore(flags); if (!card_present) goto out; } nubus_writew(0, ioaddr + ADD_PORT); sig = nubus_readw(ioaddr + DATA_PORT); if (sig != swab16(CHIP_EISA_ID_SIG)) goto out; /* Initialize the net_device structure. */ lp = netdev_priv(dev); /* Fill in the 'dev' fields. */ dev->base_addr = ioaddr; dev->mem_start = (unsigned long) nubus_slot_addr(slot) | (((slot&0xf) << 20) + MMIOBASE); dev->mem_end = dev->mem_start + 0x1000; /* Turn on shared memory */ writereg_io(dev, PP_BusCTL, MEMORY_ON); /* get the chip type */ rev_type = readreg(dev, PRODUCT_ID_ADD); lp->chip_type = rev_type &~ REVISON_BITS; lp->chip_revision = ((rev_type & REVISON_BITS) >> 8) + 'A'; /* Check the chip type and revision in order to set the correct send command CS8920 revision C and CS8900 revision F can use the faster send. */ lp->send_cmd = TX_AFTER_381; if (lp->chip_type == CS8900 && lp->chip_revision >= 'F') lp->send_cmd = TX_NOW; if (lp->chip_type != CS8900 && lp->chip_revision >= 'C') lp->send_cmd = TX_NOW; if (net_debug && version_printed++ == 0) printk(version); printk(KERN_INFO "%s: cs89%c0%s rev %c found at %#8lx", dev->name, lp->chip_type==CS8900?'0':'2', lp->chip_type==CS8920M?"M":"", lp->chip_revision, dev->base_addr); /* Try to read the MAC address */ if ((readreg(dev, PP_SelfST) & (EEPROM_PRESENT | EEPROM_OK)) == 0) { printk("\nmac89x0: No EEPROM, giving up now.\n"); goto out1; } else { for (i = 0; i < ETH_ALEN; i += 2) { /* Big-endian (why??!) */ unsigned short s = readreg(dev, PP_IA + i); dev->dev_addr[i] = s >> 8; dev->dev_addr[i+1] = s & 0xff; } } dev->irq = SLOT2IRQ(slot); /* print the IRQ and ethernet address. */ printk(" IRQ %d ADDR %pM\n", dev->irq, dev->dev_addr); dev->netdev_ops = &mac89x0_netdev_ops; err = register_netdev(dev); if (err) goto out1; return NULL; out1: nubus_writew(0, dev->base_addr + ADD_PORT); out: free_netdev(dev); return ERR_PTR(err); }
static int ad7879_i2c_write(struct device *dev, u8 reg, u16 val) { struct i2c_client *client = to_i2c_client(dev); return i2c_smbus_write_word_data(client, reg, swab16(val)); }
/* * UUID is traditionally 16 byte big-endian array, except Intel EFI * specification where the UUID is a structure of little-endian fields. */ static void swap_efi_guid(efi_guid_t *uid) { uid->time_low = swab32(uid->time_low); uid->time_mid = swab16(uid->time_mid); uid->time_hi_and_version = swab16(uid->time_hi_and_version); }
static int ad7152_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { struct ad7152_chip_info *chip = iio_priv(indio_dev); int ret, i; mutex_lock(&indio_dev->mlock); switch (mask) { case IIO_CHAN_INFO_CALIBSCALE: if (val != 1) { ret = -EINVAL; goto out; } val = (val2 * 1024) / 15625; ret = i2c_smbus_write_word_data(chip->client, ad7152_addresses[chan->channel][AD7152_GAIN], swab16(val)); if (ret < 0) goto out; ret = 0; break; case IIO_CHAN_INFO_CALIBBIAS: if ((val < 0) | (val > 0xFFFF)) { ret = -EINVAL; goto out; } ret = i2c_smbus_write_word_data(chip->client, ad7152_addresses[chan->channel][AD7152_OFFS], swab16(val)); if (ret < 0) goto out; ret = 0; break; case IIO_CHAN_INFO_SCALE: if (val != 0) { ret = -EINVAL; goto out; } for (i = 0; i < ARRAY_SIZE(ad7152_scale_table); i++) if (val2 == ad7152_scale_table[i]) break; chip->setup[chan->channel] &= ~AD7152_SETUP_RANGE_4pF; chip->setup[chan->channel] |= AD7152_SETUP_RANGE(i); ret = i2c_smbus_write_byte_data(chip->client, ad7152_addresses[chan->channel][AD7152_SETUP], chip->setup[chan->channel]); if (ret < 0) goto out; ret = 0; break; default: ret = -EINVAL; } out: mutex_unlock(&indio_dev->mlock); return ret; }
static int init586(struct net_device *dev) { void *ptr; int i,result=0; struct priv *p = (struct priv *) dev->priv; volatile struct configure_cmd_struct *cfg_cmd; volatile struct iasetup_cmd_struct *ias_cmd; volatile struct tdr_cmd_struct *tdr_cmd; volatile struct mcsetup_cmd_struct *mc_cmd; struct dev_mc_list *dmi=dev->mc_list; int num_addrs=dev->mc_count; ptr = (void *) ((char *)p->scb + sizeof(struct scb_struct)); cfg_cmd = (struct configure_cmd_struct *)ptr; /* configure-command */ cfg_cmd->cmd_status = 0; cfg_cmd->cmd_cmd = swab16(CMD_CONFIGURE | CMD_LAST); cfg_cmd->cmd_link = 0xffff; cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */ cfg_cmd->fifo = fifo; /* fifo-limit (8=tx:32/rx:64) */ cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */ cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */ cfg_cmd->priority = 0x00; cfg_cmd->ifs = 0x60; cfg_cmd->time_low = 0x00; cfg_cmd->time_high = 0xf2; cfg_cmd->promisc = 0; if(dev->flags & IFF_ALLMULTI) { int len = ((char *) p->iscp - (char *) ptr - 8) / 6; if(num_addrs > len) { printk("%s: switching to promisc. mode\n",dev->name); dev->flags|=IFF_PROMISC; } } if(dev->flags&IFF_PROMISC) { cfg_cmd->promisc=1; dev->flags|=IFF_PROMISC; } cfg_cmd->carr_coll = 0x00; p->scb->cbl_offset = make16(cfg_cmd); p->scb->cmd_ruc = 0; p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */ sun3_attn586(); WAIT_4_STAT_COMPL(cfg_cmd); if((swab16(cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != (STAT_COMPL|STAT_OK)) { printk("%s: configure command failed: %x\n",dev->name,swab16(cfg_cmd->cmd_status)); return 1; } /* * individual address setup */ ias_cmd = (struct iasetup_cmd_struct *)ptr; ias_cmd->cmd_status = 0; ias_cmd->cmd_cmd = swab16(CMD_IASETUP | CMD_LAST); ias_cmd->cmd_link = 0xffff; memcpy((char *)&ias_cmd->iaddr,(char *) dev->dev_addr,ETH_ALEN); p->scb->cbl_offset = make16(ias_cmd); p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */ sun3_attn586(); WAIT_4_STAT_COMPL(ias_cmd); if((swab16(ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != (STAT_OK|STAT_COMPL)) { printk("%s (82586): individual address setup command failed: %04x\n",dev->name,swab16(ias_cmd->cmd_status)); return 1; } /* * TDR, wire check .. e.g. no resistor e.t.c */ tdr_cmd = (struct tdr_cmd_struct *)ptr; tdr_cmd->cmd_status = 0; tdr_cmd->cmd_cmd = swab16(CMD_TDR | CMD_LAST); tdr_cmd->cmd_link = 0xffff; tdr_cmd->status = 0; p->scb->cbl_offset = make16(tdr_cmd); p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */ sun3_attn586(); WAIT_4_STAT_COMPL(tdr_cmd); if(!(swab16(tdr_cmd->cmd_status) & STAT_COMPL)) { printk("%s: Problems while running the TDR.\n",dev->name); } else { DELAY_16(); /* wait for result */ result = swab16(tdr_cmd->status); p->scb->cmd_cuc = p->scb->cus & STAT_MASK; sun3_attn586(); /* ack the interrupts */ if(result & TDR_LNK_OK) ; else if(result & TDR_XCVR_PRB) printk("%s: TDR: Transceiver problem. Check the cable(s)!\n",dev->name); else if(result & TDR_ET_OPN) printk("%s: TDR: No correct termination %d clocks away.\n",dev->name,result & TDR_TIMEMASK); else if(result & TDR_ET_SRT) { if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */ printk("%s: TDR: Detected a short circuit %d clocks away.\n",dev->name,result & TDR_TIMEMASK); } else printk("%s: TDR: Unknown status %04x\n",dev->name,result); } /* * Multicast setup */ if(num_addrs && !(dev->flags & IFF_PROMISC) ) { mc_cmd = (struct mcsetup_cmd_struct *) ptr; mc_cmd->cmd_status = 0; mc_cmd->cmd_cmd = swab16(CMD_MCSETUP | CMD_LAST); mc_cmd->cmd_link = 0xffff; mc_cmd->mc_cnt = swab16(num_addrs * 6); for(i=0;i<num_addrs;i++,dmi=dmi->next) memcpy((char *) mc_cmd->mc_list[i], dmi->dmi_addr,6); p->scb->cbl_offset = make16(mc_cmd); p->scb->cmd_cuc = CUC_START; sun3_attn586(); WAIT_4_STAT_COMPL(mc_cmd); if( (swab16(mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) ) printk("%s: Can't apply multicast-address-list.\n",dev->name); } /* * alloc nop/xmit-cmds */ #if (NUM_XMIT_BUFFS == 1) for(i=0;i<2;i++) { p->nop_cmds[i] = (struct nop_cmd_struct *)ptr; p->nop_cmds[i]->cmd_cmd = swab16(CMD_NOP); p->nop_cmds[i]->cmd_status = 0; p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i])); ptr = (char *) ptr + sizeof(struct nop_cmd_struct); } #else for(i=0;i<NUM_XMIT_BUFFS;i++) { p->nop_cmds[i] = (struct nop_cmd_struct *)ptr; p->nop_cmds[i]->cmd_cmd = swab16(CMD_NOP); p->nop_cmds[i]->cmd_status = 0; p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i])); ptr = (char *) ptr + sizeof(struct nop_cmd_struct); } #endif ptr = alloc_rfa(dev,(void *)ptr); /* init receive-frame-area */ /* * alloc xmit-buffs / init xmit_cmds */ for(i=0;i<NUM_XMIT_BUFFS;i++) { p->xmit_cmds[i] = (struct transmit_cmd_struct *)ptr; /*transmit cmd/buff 0*/ ptr = (char *) ptr + sizeof(struct transmit_cmd_struct); p->xmit_cbuffs[i] = (char *)ptr; /* char-buffs */ ptr = (char *) ptr + XMIT_BUFF_SIZE; p->xmit_buffs[i] = (struct tbd_struct *)ptr; /* TBD */ ptr = (char *) ptr + sizeof(struct tbd_struct); if((void *)ptr > (void *)dev->mem_end) { printk("%s: not enough shared-mem for your configuration!\n",dev->name); return 1; } memset((char *)(p->xmit_cmds[i]) ,0, sizeof(struct transmit_cmd_struct)); memset((char *)(p->xmit_buffs[i]),0, sizeof(struct tbd_struct)); p->xmit_cmds[i]->cmd_link = make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]); p->xmit_cmds[i]->cmd_status = swab16(STAT_COMPL); p->xmit_cmds[i]->cmd_cmd = swab16(CMD_XMIT | CMD_INT); p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i])); p->xmit_buffs[i]->next = 0xffff; p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i])); } p->xmit_count = 0; p->xmit_last = 0; #ifndef NO_NOPCOMMANDS p->nop_point = 0; #endif /* * 'start transmitter' */ #ifndef NO_NOPCOMMANDS p->scb->cbl_offset = make16(p->nop_cmds[0]); p->scb->cmd_cuc = CUC_START; sun3_attn586(); WAIT_4_SCB_CMD(); #else p->xmit_cmds[0]->cmd_link = make16(p->xmit_cmds[0]); p->xmit_cmds[0]->cmd_cmd = swab16(CMD_XMIT | CMD_SUSPEND | CMD_INT); #endif /* * ack. interrupts */ p->scb->cmd_cuc = p->scb->cus & STAT_MASK; sun3_attn586(); DELAY_16(); sun3_enaint(); sun3_active(); return 0; }
static int ad7152_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { struct ad7152_chip_info *chip = iio_priv(indio_dev); int ret; u8 regval = 0; mutex_lock(&indio_dev->mlock); switch (mask) { case 0: /* First set whether in differential mode */ regval = chip->setup[chan->channel]; if (chan->differential) chip->setup[chan->channel] |= AD7152_SETUP_CAPDIFF; else chip->setup[chan->channel] &= ~AD7152_SETUP_CAPDIFF; if (regval != chip->setup[chan->channel]) { ret = i2c_smbus_write_byte_data(chip->client, ad7152_addresses[chan->channel][AD7152_SETUP], chip->setup[chan->channel]); if (ret < 0) goto out; } /* Make sure the channel is enabled */ if (chan->channel == 0) regval = AD7152_CONF_CH1EN; else regval = AD7152_CONF_CH2EN; /* Trigger a single read */ regval |= AD7152_CONF_MODE_SINGLE_CONV; ret = i2c_smbus_write_byte_data(chip->client, AD7152_REG_CFG, regval); if (ret < 0) goto out; msleep(ad7152_filter_rate_table[chip->filter_rate_setup][1]); /* Now read the actual register */ ret = i2c_smbus_read_word_data(chip->client, ad7152_addresses[chan->channel][AD7152_DATA]); if (ret < 0) goto out; *val = swab16(ret); if (chan->differential) *val -= 0x8000; ret = IIO_VAL_INT; break; case IIO_CHAN_INFO_CALIBSCALE: ret = i2c_smbus_read_word_data(chip->client, ad7152_addresses[chan->channel][AD7152_GAIN]); if (ret < 0) goto out; /* 1 + gain_val / 2^16 */ *val = 1; *val2 = (15625 * swab16(ret)) / 1024; ret = IIO_VAL_INT_PLUS_MICRO; break; case IIO_CHAN_INFO_CALIBBIAS: ret = i2c_smbus_read_word_data(chip->client, ad7152_addresses[chan->channel][AD7152_OFFS]); if (ret < 0) goto out; *val = swab16(ret); ret = IIO_VAL_INT; break; case IIO_CHAN_INFO_SCALE: ret = i2c_smbus_read_byte_data(chip->client, ad7152_addresses[chan->channel][AD7152_SETUP]); if (ret < 0) goto out; *val = 0; *val2 = ad7152_scale_table[ret >> 6]; ret = IIO_VAL_INT_PLUS_NANO; break; default: ret = -EINVAL; }; out: mutex_unlock(&indio_dev->mlock); return ret; }
static int sun3_82586_send_packet(struct sk_buff *skb, struct net_device *dev) { int len,i; #ifndef NO_NOPCOMMANDS int next_nop; #endif struct priv *p = (struct priv *) dev->priv; if(skb->len > XMIT_BUFF_SIZE) { printk("%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n",dev->name,XMIT_BUFF_SIZE,skb->len); return 0; } netif_stop_queue(dev); #if(NUM_XMIT_BUFFS > 1) if(test_and_set_bit(0,(void *) &p->lock)) { printk("%s: Queue was locked\n",dev->name); return 1; } else #endif { len = skb->len; if (len < ETH_ZLEN) { memset((void *)p->xmit_cbuffs[p->xmit_count], 0, ETH_ZLEN); len = ETH_ZLEN; } skb_copy_from_linear_data(skb, (void *)p->xmit_cbuffs[p->xmit_count], skb->len); #if (NUM_XMIT_BUFFS == 1) # ifdef NO_NOPCOMMANDS #ifdef DEBUG if(p->scb->cus & CU_ACTIVE) { printk("%s: Hmmm .. CU is still running and we wanna send a new packet.\n",dev->name); printk("%s: stat: %04x %04x\n",dev->name,p->scb->cus,swab16(p->xmit_cmds[0]->cmd_status)); } #endif p->xmit_buffs[0]->size = swab16(TBD_LAST | len); for(i=0;i<16;i++) { p->xmit_cmds[0]->cmd_status = 0; WAIT_4_SCB_CMD(); if( (p->scb->cus & CU_STATUS) == CU_SUSPEND) p->scb->cmd_cuc = CUC_RESUME; else { p->scb->cbl_offset = make16(p->xmit_cmds[0]); p->scb->cmd_cuc = CUC_START; } sun3_attn586(); dev->trans_start = jiffies; if(!i) dev_kfree_skb(skb); WAIT_4_SCB_CMD(); if( (p->scb->cus & CU_ACTIVE)) /* test it, because CU sometimes doesn't start immediately */ break; if(p->xmit_cmds[0]->cmd_status) break; if(i==15) printk("%s: Can't start transmit-command.\n",dev->name); } # else next_nop = (p->nop_point + 1) & 0x1; p->xmit_buffs[0]->size = swab16(TBD_LAST | len); p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link = make16((p->nop_cmds[next_nop])); p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0; p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0])); dev->trans_start = jiffies; p->nop_point = next_nop; dev_kfree_skb(skb); # endif #else p->xmit_buffs[p->xmit_count]->size = swab16(TBD_LAST | len); if( (next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS ) next_nop = 0; p->xmit_cmds[p->xmit_count]->cmd_status = 0; /* linkpointer of xmit-command already points to next nop cmd */ p->nop_cmds[next_nop]->cmd_link = make16((p->nop_cmds[next_nop])); p->nop_cmds[next_nop]->cmd_status = 0; p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count])); dev->trans_start = jiffies; p->xmit_count = next_nop; { unsigned long flags; local_irq_save(flags); if(p->xmit_count != p->xmit_last) netif_wake_queue(dev); p->lock = 0; local_irq_restore(flags); } dev_kfree_skb(skb); #endif } return 0; }
/* 565RLE image format: [count(2 bytes), rle(2 bytes)] */ int load_565rle_image(char *filename) { struct fb_info *info; int fd, err = 0; unsigned count, max, width, stride, line_pos = 0; unsigned short *data, *ptr; unsigned char *bits; info = registered_fb[0]; if (!info) { printk(KERN_WARNING "%s: Can not access framebuffer\n", __func__); return -ENODEV; } fd = sys_open(filename, O_RDONLY, 0); if (fd < 0) { printk(KERN_WARNING "%s: Can not open %s\n", __func__, filename); return -ENOENT; } count = sys_lseek(fd, (off_t)0, 2); if (count <= 0) { err = -EIO; goto err_logo_close_file; } sys_lseek(fd, (off_t)0, 0); data = kmalloc(count, GFP_KERNEL); if (!data) { printk(KERN_WARNING "%s: Can not alloc data\n", __func__); err = -ENOMEM; goto err_logo_close_file; } if (sys_read(fd, (char *)data, count) != count) { err = -EIO; goto err_logo_free_data; } width = fb_width(info); stride = fb_linewidth(info); max = width * fb_height(info); ptr = data; bits = (unsigned char *)(info->screen_base); while (count > 3) { int n = ptr[0]; if (n > max) break; max -= n; while (n > 0) { unsigned int j = (line_pos + n > width ? width-line_pos : n); if (fb_depth(info) == 2) memset16(bits, swab16(ptr[1]), j << 1); else { unsigned int widepixel = ptr[1]; /* * Format is RGBA, but fb is big * endian so we should make widepixel * as ABGR. */ widepixel = /* red : f800 -> 000000f8 */ (widepixel & 0xf800) >> 8 | /* green : 07e0 -> 0000fc00 */ (widepixel & 0x07e0) << 5 | /* blue : 001f -> 00f80000 */ (widepixel & 0x001f) << 19; memset32(bits, widepixel, j << 2); } bits += j * fb_depth(info); line_pos += j; n -= j; if (line_pos == width) { bits += (stride-width) * fb_depth(info); line_pos = 0; } } ptr += 2; count -= 4; } dmac_flush_range(info->screen_base, bits); err_logo_free_data: kfree(data); err_logo_close_file: sys_close(fd); return err; }
void pkt_data_push(struct eth_device *dev, u32 addr, u32 val) { addr += dev->iobase; *(volatile u16 *)(addr + 2) = swab16((u16)val); *(volatile u16 *)(addr) = swab16((u16)(val >> 16)); }
/* For reading/writing registers ISA-style */ static inline int readreg_io(struct net_device *dev, int portno) { nubus_writew(swab16(portno), dev->base_addr + ADD_PORT); return swab16(nubus_readw(dev->base_addr + DATA_PORT)); }
static u16 ads7828_read_value(struct i2c_client *client, u8 reg) { return swab16(i2c_smbus_read_word_data(client, reg)); }
void swab_uuid(uuid *uuid) { uint8_t *bytes = (uint8_t *) uuid; swab32(bytes); swab16(bytes+4); swab16(bytes+6); }