void stop_imac_ethernet(void) { void *macio, *enet; unsigned int macio_addr[5], enet_reg[6]; int len; volatile unsigned int *dbdma; macio = finddevice("/pci/mac-io"); enet = finddevice("/pci/mac-io/ethernet"); if (macio == NULL || enet == NULL) return; len = getprop(macio, "assigned-addresses", macio_addr, sizeof(macio_addr)); if (len != sizeof(macio_addr)) return; len = getprop(enet, "reg", enet_reg, sizeof(enet_reg)); if (len != sizeof(enet_reg)) return; printf("macio base %x, dma at %x & %x\n", macio_addr[2], enet_reg[2], enet_reg[4]); /* hope this is mapped... */ dbdma = (volatile unsigned int *) (macio_addr[2] + enet_reg[2]); *dbdma = 0x80; /* clear the RUN bit */ eieio(); dbdma = (volatile unsigned int *) (macio_addr[2] + enet_reg[4]); *dbdma = 0x80; /* clear the RUN bit */ eieio(); }
void dt_get_reg_format(void *node, u32 *naddr, u32 *nsize) { if (getprop(node, "#address-cells", naddr, 4) != 4) *naddr = 2; if (getprop(node, "#size-cells", nsize, 4) != 4) *nsize = 1; }
static void ebony_flashsel_fixup(void) { void *devp; u32 reg[3] = {0x0, 0x0, 0x80000}; u8 *fpga; u8 fpga_reg0 = 0x0; devp = finddevice(EBONY_FPGA_PATH); if (!devp) fatal("Couldn't locate FPGA node %s\n\r", EBONY_FPGA_PATH); if (getprop(devp, "virtual-reg", &fpga, sizeof(fpga)) != sizeof(fpga)) fatal("%s has missing or invalid virtual-reg property\n\r", EBONY_FPGA_PATH); fpga_reg0 = in_8(fpga); devp = finddevice(EBONY_SMALL_FLASH_PATH); if (!devp) fatal("Couldn't locate small flash node %s\n\r", EBONY_SMALL_FLASH_PATH); if (getprop(devp, "reg", reg, sizeof(reg)) != sizeof(reg)) fatal("%s has reg property of unexpected size\n\r", EBONY_SMALL_FLASH_PATH); /* Invert address bit 14 (IBM-endian) if FLASH_SEL fpga bit is set */ if (fpga_reg0 & EBONY_FPGA_FLASH_SEL) reg[1] ^= 0x80000; setprop(devp, "reg", reg, sizeof(reg)); }
int vbus_intr_map(int node, int ino, uint64_t *sysino) { int *imap = NULL, nimap; int *reg = NULL, nreg; int *imap_mask; int parent; int address_cells, interrupt_cells; uint64_t devhandle; uint64_t devino; int len; int err; parent = OF_parent(node); address_cells = getpropint(parent, "#address-cells", 2); interrupt_cells = getpropint(parent, "#interrupt-cells", 1); KASSERT(interrupt_cells == 1); len = OF_getproplen(parent, "interrupt-map-mask"); if (len < (address_cells + interrupt_cells) * sizeof(int)) return (-1); imap_mask = malloc(len, M_DEVBUF, M_NOWAIT); if (imap_mask == NULL) return (-1); if (OF_getprop(parent, "interrupt-map-mask", imap_mask, len) != len) return (-1); getprop(parent, "interrupt-map", sizeof(int), &nimap, (void **)&imap); getprop(node, "reg", sizeof(*reg), &nreg, (void **)®); if (nreg < address_cells) return (-1); while (nimap >= address_cells + interrupt_cells + 2) { if (vbus_cmp_cells(imap, reg, imap_mask, address_cells) && vbus_cmp_cells(&imap[address_cells], &ino, &imap_mask[address_cells], interrupt_cells)) { node = imap[address_cells + interrupt_cells]; devino = imap[address_cells + interrupt_cells + 1]; free(reg, M_DEVBUF, 0); reg = NULL; getprop(node, "reg", sizeof(*reg), &nreg, (void **)®); devhandle = reg[0] & 0x0fffffff; err = hv_intr_devino_to_sysino(devhandle, devino, sysino); if (err != H_EOK) return (-1); KASSERT(*sysino == INTVEC(*sysino)); return (0); } imap += address_cells + interrupt_cells + 2; nimap -= address_cells + interrupt_cells + 2; } return (-1); }
void wmMenuWidget::addMenuWin(Client *c){ // ICCCM calls for XA_WM_ICON_NAME here // but that doesn't quite cut it IMHO (Brian) // No Name, No listing if( !getprop(c->window,XA_WM_NAME) ) return; c->id = windows->insertItem(getprop(c->window,XA_WM_NAME),c,SLOT(unMinimize())); fprintf(stderr,"adding window with unique id %d and name %s\n",c->id,getprop(c->window,XA_WM_NAME)); connect(c,SIGNAL(clientClosed( int )), m,SLOT(removeMenuWin( int))); } /* end wmMenuWidget::addMenuWin */
void upa_attach(struct device *parent, struct device *self, void *aux) { struct upa_softc *sc = (void *)self; struct mainbus_attach_args *ma = aux; int i, node; sc->sc_bt = ma->ma_bustag; sc->sc_node = ma->ma_node; for (i = 0; i < 3; i++) { if (i >= ma->ma_nreg) { printf(": no register %d\n", i); return; } if (bus_space_map(sc->sc_bt, ma->ma_reg[i].ur_paddr, ma->ma_reg[i].ur_len, 0, &sc->sc_reg[i])) { printf(": failed to map reg%d\n", i); return; } } if (getprop(sc->sc_node, "ranges", sizeof(struct upa_range), &sc->sc_nrange, (void **)&sc->sc_range)) panic("upa: can't get ranges"); printf("\n"); sc->sc_cbt = upa_alloc_bus_tag(sc); for (node = OF_child(sc->sc_node); node; node = OF_peer(node)) { char buf[32]; struct mainbus_attach_args map; bzero(&map, sizeof(map)); if (OF_getprop(node, "device_type", buf, sizeof(buf)) <= 0) continue; if (getprop(node, "reg", sizeof(*map.ma_reg), &map.ma_nreg, (void **)&map.ma_reg) != 0) continue; if (OF_getprop(node, "name", buf, sizeof(buf)) <= 0) continue; map.ma_node = node; map.ma_name = buf; map.ma_bustag = sc->sc_cbt; map.ma_dmatag = ma->ma_dmatag; config_found(&sc->sc_dev, &map, upa_print); } }
/* Node's "compatible" property determines which serial driver to use */ int serial_console_init(void) { void *devp; int rc = -1; char compat[MAX_PROP_LEN]; devp = serial_get_stdout_devp(); if (devp == NULL) goto err_out; if (getprop(devp, "compatible", compat, sizeof(compat)) < 0) goto err_out; if (!strcmp(compat, "ns16550")) rc = ns16550_console_init(devp, &serial_cd); else if (!strcmp(compat, "marvell,mpsc")) rc = mpsc_console_init(devp, &serial_cd); /* Add other serial console driver calls here */ if (!rc) { console_ops.open = serial_open; console_ops.write = serial_write; console_ops.edit_cmdline = serial_edit_cmdline; console_ops.close = serial_close; console_ops.data = &serial_cd; return 0; } err_out: return -1; }
NODE *lremprop(NODE *args) { NODE *plname, *pname, *plist, *val = NIL; BOOLEANx caseig = FALSE; if (compare_node(valnode__caseobj(Caseignoredp), Truex, TRUE) == 0) caseig = TRUE; plname = string_arg(args); pname = string_arg(cdr(args)); if (NOT_THROWING) { plname = intern(plname); plist = plist__caseobj(plname); if (plist != NIL) { if (compare_node(car(plist), pname, caseig) == 0) setplist__caseobj(plname, cddr(plist)); else { val = getprop(plist, pname, TRUE); if (val != NIL) setcdr(cdr(val), cddr(cddr(val))); } } } return (UNBOUND); }
NODE *lpprop(NODE *args) { NODE *plname, *pname, *newval, *plist, *val = NIL; plname = string_arg(args); pname = string_arg(cdr(args)); newval = car(cddr(args)); if (NOT_THROWING) { plname = intern(plname); if (flag__caseobj(plname, PLIST_TRACED)) { ndprintf(writestream, "Pprop %s %s %s", maybe_quote(plname), maybe_quote(pname), maybe_quote(newval)); if (ufun != NIL) ndprintf(writestream, " in %s\n%s", ufun, this_line); new_line(writestream); } plist = plist__caseobj(plname); if (plist != NIL) val = getprop(plist, pname, FALSE); if (val != NIL) setcar(cdr(val), newval); else setplist__caseobj(plname, cons(pname, cons(newval, plist))); } return (UNBOUND); }
void planetcore_set_serial_speed(const char *table) { void *chosen, *stdout; u64 baud; u32 baud32; int len; chosen = finddevice("/chosen"); if (!chosen) return; len = getprop(chosen, "linux,stdout-path", prop_buf, MAX_PROP_LEN); if (len <= 0) return; stdout = finddevice(prop_buf); if (!stdout) { printf("planetcore_set_serial_speed: " "Bad /chosen/linux,stdout-path.\r\n"); return; } if (!planetcore_get_decimal(table, PLANETCORE_KEY_SERIAL_BAUD, &baud)) { printf("planetcore_set_serial_speed: No SB tag.\r\n"); return; } baud32 = baud; setprop(stdout, "current-speed", &baud32, 4); }
static void merge_fdt_bootargs(void *fdt, const char *fdt_cmdline) { char cmdline[COMMAND_LINE_SIZE]; const char *fdt_bootargs; char *ptr = cmdline; int len = 0; /* copy the fdt command line into the buffer */ fdt_bootargs = getprop(fdt, "/chosen", "bootargs", &len); if (fdt_bootargs) if (len < COMMAND_LINE_SIZE) { memcpy(ptr, fdt_bootargs, len); /* len is the length of the string * including the NULL terminator */ ptr += len - 1; } /* and append the ATAG_CMDLINE */ if (fdt_cmdline) { len = strlen(fdt_cmdline); if (ptr - cmdline + len + 2 < COMMAND_LINE_SIZE) { *ptr++ = ' '; memcpy(ptr, fdt_cmdline, len); ptr += len; } } *ptr = '\0'; setprop_string(fdt, "/chosen", "bootargs", cmdline); }
int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size) { int reglen; reglen = getprop(node, "reg", prop_buf, sizeof(prop_buf)) / 4; return dt_xlate(node, res, reglen, addr, size); }
static void platform_fixups(void) { u64 val; void *nvrtc; dt_fixup_memory(0, mem_size); planetcore_set_mac_addrs(table); if (!planetcore_get_decimal(table, PLANETCORE_KEY_CRYSTAL_HZ, &val)) { printf("No PlanetCore crystal frequency key.\r\n"); return; } ibm405gp_fixup_clocks(val, 0xa8c000); ibm4xx_quiesce_eth((u32 *)0xef600800, NULL); ibm4xx_fixup_ebc_ranges("/plb/ebc"); if (!planetcore_get_decimal(table, PLANETCORE_KEY_KB_NVRAM, &val)) { printf("No PlanetCore NVRAM size key.\r\n"); return; } nvrtc = finddevice("/plb/ebc/nvrtc@4,200000"); if (nvrtc != NULL) { u32 reg[3] = { 4, 0x200000, 0}; getprop(nvrtc, "reg", reg, 3); reg[2] = (val << 10) & 0xffffffff; setprop(nvrtc, "reg", reg, 3); } }
static int virtex_ns16550_console_init(void *devp) { unsigned char *reg_base; u32 reg_shift, reg_offset, clk, spd; u16 divisor; int n; if (dt_get_virtual_reg(devp, (void **)®_base, 1) < 1) return -1; n = getprop(devp, "reg-offset", ®_offset, sizeof(reg_offset)); if (n == sizeof(reg_offset)) reg_base += reg_offset; n = getprop(devp, "reg-shift", ®_shift, sizeof(reg_shift)); if (n != sizeof(reg_shift)) reg_shift = 0; n = getprop(devp, "current-speed", (void *)&spd, sizeof(spd)); if (n != sizeof(spd)) spd = 9600; /* should there be a default clock rate?*/ n = getprop(devp, "clock-frequency", (void *)&clk, sizeof(clk)); if (n != sizeof(clk)) return -1; divisor = clk / (16 * spd); /* Access baud rate */ out_8(reg_base + (UART_LCR << reg_shift), UART_LCR_DLAB); /* Baud rate based on input clock */ out_8(reg_base + (UART_DLL << reg_shift), divisor & 0xFF); out_8(reg_base + (UART_DLM << reg_shift), divisor >> 8); /* 8 data, 1 stop, no parity */ out_8(reg_base + (UART_LCR << reg_shift), UART_LCR_WLEN8); /* RTS/DTR */ out_8(reg_base + (UART_MCR << reg_shift), UART_MCR_RTS | UART_MCR_DTR); /* Clear transmitter and receiver */ out_8(reg_base + (UART_FCR << reg_shift), UART_FCR_CLEAR_XMIT | UART_FCR_CLEAR_RCVR); return 0; }
void start(int a1, int a2, void *promptr) { prom = (int (*)(void *)) promptr; chosen_handle = finddevice("/chosen"); if (chosen_handle == (void *) -1) exit(); if (getprop(chosen_handle, "stdout", &stdout, sizeof(stdout)) != 4) exit(); stderr = stdout; if (getprop(chosen_handle, "stdin", &stdin, sizeof(stdin)) != 4) exit(); chrpboot(a1, a2, promptr); for (;;) exit(); }
int dt_get_virtual_reg(void *node, void **addr, int nres) { unsigned long xaddr; int n; n = getprop(node, "virtual-reg", addr, nres * 4); if (n > 0) return n / 4;
int mpsc_console_init(void *devp, struct serial_console_data *scdp) { void *v; int n, reg_set; volatile char *sdma_base; n = getprop(devp, "virtual-reg", &v, sizeof(v)); if (n != sizeof(v)) goto err_out; mpsc_base = v; sdma_base = mpsc_get_virtreg_of_phandle(devp, "sdma"); if (sdma_base == NULL) goto err_out; mpscintr_base = mpsc_get_virtreg_of_phandle(devp, "mpscintr"); if (mpscintr_base == NULL) goto err_out; n = getprop(devp, "cell-index", &v, sizeof(v)); if (n != sizeof(v)) goto err_out; reg_set = (int)v; mpscintr_base += (reg_set == 0) ? 0x4 : 0xc; /* Make sure the mpsc ctlrs are shutdown */ out_le32((u32 *)(mpscintr_base + MPSC_INTR_CAUSE), 0); out_le32((u32 *)(mpscintr_base + MPSC_INTR_CAUSE), 0); out_le32((u32 *)(mpscintr_base + MPSC_INTR_MASK), 0); out_le32((u32 *)(mpscintr_base + MPSC_INTR_MASK), 0); mpsc_stop_dma(sdma_base); scdp->open = mpsc_open; scdp->putc = mpsc_putc; scdp->getc = mpsc_getc; scdp->tstc = mpsc_tstc; scdp->close = NULL; return 0; err_out: return -1; }
static void prep_cmdline(void *chosen) { if (cmdline[0] == '\0') getprop(chosen, "bootargs", cmdline, COMMAND_LINE_SIZE-1); else setprop_str(chosen, "bootargs", cmdline); printf("cmdline: '%s'\n", cmdline); }
static uint32_t get_cell_size(const void *fdt) { int len; uint32_t cell_size = 1; const uint32_t *size_len = getprop(fdt, "/", "#size-cells", &len); if (size_len) cell_size = fdt32_to_cpu(*size_len); return cell_size; }
int ns16550_console_init(void *devp, struct serial_console_data *scdp) { int n; n = getprop(devp, "virtual-reg", ®_base, sizeof(reg_base)); if (n != sizeof(reg_base)) return -1; n = getprop(devp, "reg-shift", ®_shift, sizeof(reg_shift)); if (n != sizeof(reg_shift)) reg_shift = 0; scdp->open = ns16550_open; scdp->putc = ns16550_putc; scdp->getc = ns16550_getc; scdp->tstc = ns16550_tstc; scdp->close = NULL; return 0; }
static volatile char *mpsc_get_virtreg_of_phandle(void *devp, char *prop) { void *v; int n; n = getprop(devp, prop, &v, sizeof(v)); if (n != sizeof(v)) goto err_out; devp = find_node_by_linuxphandle((u32)v); if (devp == NULL) goto err_out; n = getprop(devp, "virtual-reg", &v, sizeof(v)); if (n == sizeof(v)) return v; err_out: return NULL; }
int ofstdio(ihandle *stdin, ihandle *stdout, ihandle *stderr) { ihandle in, out; phandle chosen; if ((chosen = finddevice("/chosen")) == OF_INVALID_HANDLE) goto err; if (getprop(chosen, "stdout", &out, sizeof(out)) != 4) goto err; if (getprop(chosen, "stdin", &in, sizeof(in)) != 4) goto err; *stdin = in; *stdout = out; *stderr = out; return 0; err: return -1; }
static int of_console_open(void) { void *devp; if (((devp = finddevice("/chosen")) != NULL) && (getprop(devp, "stdout", &of_stdout_handle, sizeof(of_stdout_handle)) == sizeof(of_stdout_handle))) return 0; return -1; }
static void *serial_get_stdout_devp(void) { void *devp; char devtype[MAX_PROP_LEN]; char path[MAX_PATH_LEN]; devp = finddevice("/chosen"); if (devp == NULL) goto err_out; if (getprop(devp, "linux,stdout-path", path, MAX_PATH_LEN) > 0) { devp = finddevice(path); if (devp == NULL) goto err_out; if ((getprop(devp, "device_type", devtype, sizeof(devtype)) > 0) && !strcmp(devtype, "serial")) return devp; } err_out: return NULL; }
/* For virtex, the kernel may be loaded without using a bootloader and if so some UARTs need more setup than is provided in the normal console init */ int platform_specific_init(void) { void *devp; char devtype[MAX_PROP_LEN]; char path[MAX_PATH_LEN]; devp = finddevice("/chosen"); if (devp == NULL) return -1; if (getprop(devp, "linux,stdout-path", path, MAX_PATH_LEN) > 0) { devp = finddevice(path); if (devp == NULL) return -1; if ((getprop(devp, "device_type", devtype, sizeof(devtype)) > 0) && !strcmp(devtype, "serial") && (dt_is_compatible(devp, "ns16550"))) virtex_ns16550_console_init(devp); } return 0; }
void dt_fixup_memory(u64 start, u64 size) { void *root, *memory; int naddr, nsize, i; u32 memreg[4]; root = finddevice("/"); if (getprop(root, "#address-cells", &naddr, sizeof(naddr)) < 0) naddr = 2; if (naddr < 1 || naddr > 2) fatal("Can't cope with #address-cells == %d in /\n\r", naddr); if (getprop(root, "#size-cells", &nsize, sizeof(nsize)) < 0) nsize = 1; if (nsize < 1 || nsize > 2) fatal("Can't cope with #size-cells == %d in /\n\r", nsize); i = 0; if (naddr == 2) memreg[i++] = start >> 32; memreg[i++] = start & 0xffffffff; if (nsize == 2) memreg[i++] = size >> 32; memreg[i++] = size & 0xffffffff; memory = finddevice("/memory"); if (! memory) { memory = create_node(NULL, "memory"); setprop_str(memory, "device_type", "memory"); } printf("Memory <- <0x%x", memreg[0]); for (i = 1; i < (naddr + nsize); i++) printf(" 0x%x", memreg[i]); printf("> (%ldMB)\n\r", (unsigned long)(size >> 20)); setprop(memory, "reg", memreg, (naddr + nsize)*sizeof(u32)); }
static int check_of_version(void) { phandle oprom, chosen; char version[64]; oprom = finddevice("/openprom"); if (oprom == (phandle) -1) return 0; if (getprop(oprom, "model", version, sizeof(version)) <= 0) return 0; version[sizeof(version)-1] = 0; printf("OF version = '%s'\r\n", version); if (!string_match(version, "Open Firmware, 1.") && !string_match(version, "FirmWorks,3.")) return 0; chosen = finddevice("/chosen"); if (chosen == (phandle) -1) { chosen = finddevice("/chosen@0"); if (chosen == (phandle) -1) { printf("no chosen\n"); return 0; } } if (getprop(chosen, "mmu", &chosen_mmu, sizeof(chosen_mmu)) <= 0) { printf("no mmu\n"); return 0; } memory = (ihandle) call_prom("open", 1, 1, "/memory"); if (memory == (ihandle) -1) { memory = (ihandle) call_prom("open", 1, 1, "/memory@0"); if (memory == (ihandle) -1) { printf("no memory node\n"); return 0; } } printf("old OF detected\r\n"); return 1; }
void vbus_attach(struct device *parent, struct device *self, void *aux) { struct vbus_softc *sc = (struct vbus_softc *)self; struct mainbus_attach_args *ma = aux; int node; sc->sc_bustag = vbus_alloc_bus_tag(sc, ma->ma_bustag); sc->sc_dmatag = ma->ma_dmatag; printf("\n"); for (node = OF_child(ma->ma_node); node; node = OF_peer(node)) { struct vbus_attach_args va; char buf[32]; bzero(&va, sizeof(va)); va.va_node = node; if (OF_getprop(node, "name", buf, sizeof(buf)) <= 0) continue; va.va_name = buf; va.va_bustag = sc->sc_bustag; va.va_dmatag = sc->sc_dmatag; getprop(node, "reg", sizeof(*va.va_reg), &va.va_nreg, (void **)&va.va_reg); getprop(node, "interrupts", sizeof(*va.va_intr), &va.va_nintr, (void **)&va.va_intr); config_found(self, &va, vbus_print); } if (todr_handle == NULL) { struct vbus_attach_args va; bzero(&va, sizeof(va)); va.va_name = "rtc"; config_found(self, &va, vbus_print); } }
static void get_cmdline(char *buf, int size) { void *devp; int len = strlen(builtin_cmdline); buf[0] = '\0'; if (len > 0) { /* builtin_cmdline overrides dt's /chosen/bootargs */ len = min(len, size-1); strncpy(buf, builtin_cmdline, len); buf[len] = '\0'; } else if ((devp = finddevice("/chosen"))) getprop(devp, "bootargs", buf, size); }
void export_cmdline(void* chosen_handle) { int len; char cmdline[2] = { 0, 0 }; if (builtin_cmdline[0] == 0) return; len = getprop(chosen_handle, "bootargs", cmdline, sizeof(cmdline)); if (len > 0 && cmdline[0] != 0) return; setprop(chosen_handle, "bootargs", builtin_cmdline, strlen(builtin_cmdline) + 1); }