Example #1
0
void __init
chrp_find_bridges(void)
{
	struct device_node *dev;
	int *bus_range;
	int len, index = -1;
	struct pci_controller *hose;
	unsigned int *dma;
	char *model, *machine;
	int is_longtrail = 0, is_mot = 0;
	struct device_node *root = find_path_device("/");

	/*
	 * The PCI host bridge nodes on some machines don't have
	 * properties to adequately identify them, so we have to
	 * look at what sort of machine this is as well.
	 */
	machine = get_property(root, "model", NULL);
	if (machine != NULL) {
		is_longtrail = strncmp(machine, "IBM,LongTrail", 13) == 0;
		is_mot = strncmp(machine, "MOT", 3) == 0;
	}
	for (dev = root->child; dev != NULL; dev = dev->sibling) {
		if (dev->type == NULL || strcmp(dev->type, "pci") != 0)
			continue;
		++index;
		/* The GG2 bridge on the LongTrail doesn't have an address */
		if (dev->n_addrs < 1 && !is_longtrail) {
			printk(KERN_WARNING "Can't use %s: no address\n",
			       dev->full_name);
			continue;
		}
		bus_range = (int *) get_property(dev, "bus-range", &len);
		if (bus_range == NULL || len < 2 * sizeof(int)) {
			printk(KERN_WARNING "Can't get bus-range for %s\n",
				dev->full_name);
			continue;
		}
		if (bus_range[1] == bus_range[0])
			printk(KERN_INFO "PCI bus %d", bus_range[0]);
		else
			printk(KERN_INFO "PCI buses %d..%d",
			       bus_range[0], bus_range[1]);
		printk(" controlled by %s", dev->type);
		if (dev->n_addrs > 0)
			printk(" at %x", dev->addrs[0].address);
		printk("\n");

		hose = pcibios_alloc_controller();
		if (!hose) {
			printk("Can't allocate PCI controller structure for %s\n",
				dev->full_name);
			continue;
		}
		hose->arch_data = dev;
		hose->first_busno = bus_range[0];
		hose->last_busno = bus_range[1];

		model = get_property(dev, "model", NULL);
		if (model == NULL)
			model = "<none>";
		if (device_is_compatible(dev, "IBM,python")) {
			setup_python(hose, dev);
		} else if (is_mot
			   || strncmp(model, "Motorola, Grackle", 17) == 0) {
			setup_grackle(hose);
		} else if (is_longtrail) {
			hose->ops = &gg2_pci_ops;
			gg2_pci_config_base = (unsigned long)
				ioremap(GG2_PCI_CONFIG_BASE, 0x80000);
		} else if (!strncmp(model, "IBM,CPC710", 10)) {
			setup_indirect_pci(hose,
				dev->addrs[0].address + 0x000f8000,
				dev->addrs[0].address + 0x000f8010);
			if (index == 0) {
				dma = (unsigned int *)
					get_property(dev, "system-dma-base", &len);
			 	if (dma && len >= sizeof(*dma)) {
					dma = (unsigned int *)(((unsigned long)dma) +
						len - sizeof(*dma));
					pci_dram_offset = *dma;
				}
			}
		} else {
			printk("No methods for %s (model %s), using RTAS\n",
			       dev->full_name, model);
			hose->ops = &rtas_pci_ops;
		}

		pci_process_bridge_OF_ranges(hose, dev, index == 0);

		/* check the first bridge for a property that we can
		   use to set pci_dram_offset */
		dma = (unsigned int *)
			get_property(dev, "ibm,dma-ranges", &len);
		if (index == 0 && dma != NULL && len >= 6 * sizeof(*dma)) {
			pci_dram_offset = dma[2] - dma[3];
			printk("pci_dram_offset = %lx\n", pci_dram_offset);
		}
	}

	ppc_md.pcibios_fixup = chrp_pcibios_fixup;
}
static int
update_cpu_node(struct dr_node *cpu, const char *path, struct dr_info *dr_info)
{
	struct stat sb;
	char intserv_path[DR_PATH_MAX];
	int rc;

	if (path) {
		snprintf(cpu->ofdt_path, DR_PATH_MAX, "%s", path);
	} else {
		rc = cpu_index_to_path(cpu);
		if (rc) {
			say(ERROR, "Could not find ofdt path for drc index "
			    "%s\n", cpu->drc_index);
			return rc;
		}
	}

	/* Skip past CPU_OFDT_BASE plus the '/' */
	cpu->name = cpu->ofdt_path + strlen(CPU_OFDT_BASE) + 1;

	memset(&cpu->cpu_intserv_nums, -1, sizeof(cpu->cpu_intserv_nums));
	rc = get_property(cpu->ofdt_path, "ibm,ppc-interrupt-server#s",
			  &cpu->cpu_intserv_nums,
			  sizeof(cpu->cpu_intserv_nums));
	if (rc) {
		say(ERROR, "Could not retrieve ibm,ppc-interrupt-server#s "
		    "property for %s\n", cpu->name);
		return -1;
	}

	/* The number of threads is the number of 32-bit ints in the
	 * cpu's ibm,ppc-interrupt-server#s property.
	 */
	sprintf(intserv_path,
		"/proc/device-tree/cpus/%s/ibm,ppc-interrupt-server#s",
		strstr(cpu->name, "PowerPC"));

	if (stat(intserv_path, &sb))
		/* Assume no SMT */
		cpu->cpu_nthreads = 1;
	else
		cpu->cpu_nthreads = sb.st_size / 4;

	rc = get_property(cpu->ofdt_path, "reg", &cpu->cpu_reg,
			  sizeof(cpu->cpu_reg));
	if (rc) {
		say(ERROR, "Could not retrieve reg property for %s\n",
		    cpu->name);
		return -1;
	}

	/* l2-cache may not exist */
	cpu->cpu_l2cache = 0xffffffff;
	get_property(cpu->ofdt_path, "l2-cache", &cpu->cpu_l2cache,
		     sizeof(cpu->cpu_l2cache));

	get_cpu_threads(cpu, dr_info->all_threads);
	cpu->is_owned = 1;
	return 0;
}
Example #3
0
void
reflist_del(dbref obj, const char *propname, dbref todel)
{
    PropPtr ptr;
    const char *temp;
    const char *list;
    int count = 0;
    int charcount = 0;
    char buf[BUFFER_LEN];
    char outbuf[BUFFER_LEN];

    ptr = get_property(obj, propname);
    if (ptr) {
        const char *pat = NULL;

#ifdef DISKBASE
        propfetch(obj, ptr);
#endif
        switch (PropType(ptr)) {
            case PROP_STRTYP:
                *outbuf = '\0';
                list = temp = uncompress(PropDataStr(ptr));
                sprintf(buf, "%d", todel);
                while (*temp) {
                    if (*temp == '#') {
                        pat = buf;
                        count++;
                        charcount = temp - list;
                    } else if (pat) {
                        if (!*pat) {
                            if (!*temp || *temp == ' ') {
                                break;
                            }
                            pat = NULL;
                        } else if (*pat != *temp) {
                            pat = NULL;
                        } else {
                            pat++;
                        }
                    }
                    temp++;
                }
                if (pat && !*pat) {
                    if (charcount > 0) {
                        strncpy(outbuf, list, charcount - 1);
                        outbuf[charcount - 1] = '\0';
                    }
                    strcat(outbuf, temp);
                    for (temp = outbuf; isspace(*temp); temp++) ;
                    add_property(obj, propname, temp, 0);
                }
                break;
            case PROP_REFTYP:
                if (PropDataRef(ptr) == todel) {
                    add_property(obj, propname, "", 0);
                }
                break;
            default:
                break;
        }
    }
}
/*
 * This is called very early, as part of setup_system() or eventually
 * setup_arch(), basically before anything else in this file. This function
 * will try to build a list of all the available 8250-compatible serial ports
 * in the machine using the Open Firmware device-tree. It currently only deals
 * with ISA and PCI busses but could be extended. It allows a very early boot
 * console to be initialized, that list is also used later to provide 8250 with
 * the machine non-PCI ports and to properly pick the default console port
 */
void __init find_legacy_serial_ports(void)
{
	struct device_node *np, *stdout = NULL;
	const char *path;
	int index;

	DBG(" -> find_legacy_serial_port()\n");

	/* Now find out if one of these is out firmware console */
	path = get_property(of_chosen, "linux,stdout-path", NULL);
	if (path != NULL) {
		stdout = of_find_node_by_path(path);
		if (stdout)
			DBG("stdout is %s\n", stdout->full_name);
	} else {
		DBG(" no linux,stdout-path !\n");
	}

	/* First fill our array with SOC ports */
	for (np = NULL; (np = of_find_compatible_node(np, "serial", "ns16550")) != NULL;) {
		struct device_node *soc = of_get_parent(np);
		if (soc && !strcmp(soc->type, "soc")) {
			index = add_legacy_soc_port(np, np);
			if (index >= 0 && np == stdout)
				legacy_serial_console = index;
		}
		of_node_put(soc);
	}

	/* First fill our array with ISA ports */
	for (np = NULL; (np = of_find_node_by_type(np, "serial"));) {
		struct device_node *isa = of_get_parent(np);
		if (isa && !strcmp(isa->name, "isa")) {
			index = add_legacy_isa_port(np, isa);
			if (index >= 0 && np == stdout)
				legacy_serial_console = index;
		}
		of_node_put(isa);
	}

	/* First fill our array with tsi-bridge ports */
	for (np = NULL; (np = of_find_compatible_node(np, "serial", "ns16550")) != NULL;) {
		struct device_node *tsi = of_get_parent(np);
		if (tsi && !strcmp(tsi->type, "tsi-bridge")) {
			index = add_legacy_soc_port(np, np);
			if (index >= 0 && np == stdout)
				legacy_serial_console = index;
		}
		of_node_put(tsi);
	}

	/* First fill our array with opb bus ports */
	for (np = NULL; (np = of_find_compatible_node(np, "serial", "ns16750")) != NULL;) {
		struct device_node *opb = of_get_parent(np);
		if (opb && !strcmp(opb->type, "opb")) {
			index = add_legacy_soc_port(np, np);
			if (index >= 0 && np == stdout)
				legacy_serial_console = index;
		}
		of_node_put(opb);
	}

#ifdef CONFIG_PCI
	/* Next, try to locate PCI ports */
	for (np = NULL; (np = of_find_all_nodes(np));) {
		struct device_node *pci, *parent = of_get_parent(np);
		if (parent && !strcmp(parent->name, "isa")) {
			of_node_put(parent);
			continue;
		}
		if (strcmp(np->name, "serial") && strcmp(np->type, "serial")) {
			of_node_put(parent);
			continue;
		}
		/* Check for known pciclass, and also check wether we have
		 * a device with child nodes for ports or not
		 */
		if (device_is_compatible(np, "pciclass,0700") ||
		    device_is_compatible(np, "pciclass,070002"))
			pci = np;
		else if (device_is_compatible(parent, "pciclass,0700") ||
			 device_is_compatible(parent, "pciclass,070002"))
			pci = parent;
		else {
			of_node_put(parent);
			continue;
		}
		index = add_legacy_pci_port(np, pci);
		if (index >= 0 && np == stdout)
			legacy_serial_console = index;
		of_node_put(parent);
	}
#endif

	DBG("legacy_serial_console = %d\n", legacy_serial_console);
	if (legacy_serial_console >= 0)
		setup_legacy_serial_console(legacy_serial_console);
	DBG(" <- find_legacy_serial_port()\n");
}
/*
 * This is called very early, as part of console_init() (typically just after
 * time_init()). This function is respondible for trying to find a good
 * default console on serial ports. It tries to match the open firmware
 * default output with one of the available serial console drivers, either
 * one of the platform serial ports that have been probed earlier by
 * find_legacy_serial_ports() or some more platform specific ones.
 */
static int __init check_legacy_serial_console(void)
{
	struct device_node *prom_stdout = NULL;
	int speed = 0, offset = 0;
	const char *name;
	const u32 *spd;

	DBG(" -> check_legacy_serial_console()\n");

	/* The user has requested a console so this is already set up. */
	if (strstr(boot_command_line, "console=")) {
		DBG(" console was specified !\n");
		return -EBUSY;
	}

	if (!of_chosen) {
		DBG(" of_chosen is NULL !\n");
		return -ENODEV;
	}

	if (legacy_serial_console < 0) {
		DBG(" legacy_serial_console not found !\n");
		return -ENODEV;
	}
	/* We are getting a weird phandle from OF ... */
	/* ... So use the full path instead */
	name = get_property(of_chosen, "linux,stdout-path", NULL);
	if (name == NULL) {
		DBG(" no linux,stdout-path !\n");
		return -ENODEV;
	}
	prom_stdout = of_find_node_by_path(name);
	if (!prom_stdout) {
		DBG(" can't find stdout package %s !\n", name);
		return -ENODEV;
	}
	DBG("stdout is %s\n", prom_stdout->full_name);

	name = get_property(prom_stdout, "name", NULL);
	if (!name) {
		DBG(" stdout package has no name !\n");
		goto not_found;
	}
	spd = get_property(prom_stdout, "current-speed", NULL);
	if (spd)
		speed = *spd;

	if (0)
		;
#ifdef CONFIG_SERIAL_8250_CONSOLE
	else if (strcmp(name, "serial") == 0) {
		int i;
		/* Look for it in probed array */
		for (i = 0; i < legacy_serial_count; i++) {
			if (prom_stdout != legacy_serial_infos[i].np)
				continue;
			offset = i;
			speed = legacy_serial_infos[i].speed;
			break;
		}
		if (i >= legacy_serial_count)
			goto not_found;
	}
#endif /* CONFIG_SERIAL_8250_CONSOLE */
#ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
	else if (strcmp(name, "ch-a") == 0)
		offset = 0;
	else if (strcmp(name, "ch-b") == 0)
		offset = 1;
#endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */
	else
		goto not_found;
	of_node_put(prom_stdout);

	DBG("Found serial console at ttyS%d\n", offset);

	if (speed) {
		static char __initdata opt[16];
		sprintf(opt, "%d", speed);
		return add_preferred_console("ttyS", offset, opt);
	} else
		return add_preferred_console("ttyS", offset, NULL);

 not_found:
	DBG("No preferred console found !\n");
	of_node_put(prom_stdout);
	return -ENODEV;
}
Example #6
0
int
property_check (const char *filename, int version, int verbose)
{
  char buf[MAXBUFSIZE];
  const char *p = NULL;
  int result = 0;

  if (access (filename, F_OK) != 0)
    {
      FILE *fh = NULL;

      if (verbose) 
        {
          fprintf (stderr, "NOTE: %s not found: creating...", filename);
          fflush (stderr);
        }

      if ((fh = fopen (filename, "w")) == NULL) // opening the file in text mode
        {                                       //  avoids trouble on DOS
          printf ("FAILED\n\n");
          return -1;
        }
      fclose (fh);                              // we'll use set_property() from now
    }
  else
    {
      p = get_property (filename, "version", PROPERTY_MODE_TEXT);
      if (strtol (p ? p : "0", NULL, 10) >= version)
        return 0;                               // OK

      strcpy (buf, filename);
      set_suffix (buf, ".old");

      if (verbose)
        {
          fprintf (stderr, "NOTE: updating config: will be renamed to %s...", buf);
          fflush (stderr);
        }

      rename (filename, buf);
    }

  // store new version
  sprintf (buf, "%d", version);
  result = set_property (filename, "version", buf, "configfile version (do NOT edit)");

  if (result > 0)
    {
      if (verbose)
        fprintf (stderr, "OK\n\n");
    }
  else
    {
      if (verbose)
        fprintf (stderr, "FAILED\n\n");

      // remove the crap
      remove (filename);
    }

  if (verbose)
    fflush (stderr);

  return 1;
}
Example #7
0
 graph_bundled const& operator[](graph_bundle_t) const
 { return get_property(*this); }
Example #8
0
    void write_graphviz_subgraph (std::ostream& out, 
                                  const subgraph<Graph_>& g, 
                                  RandomAccessIterator vertex_marker,
                                  RandomAccessIterator edge_marker)
    {
      typedef subgraph<Graph_> Graph;
      typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
      typedef typename boost::graph_traits<Graph>::directed_category cat_type;
      typedef graphviz_io_traits<cat_type> Traits;

      typedef typename graph_property<Graph, graph_name_t>::type NameType;
      const NameType& g_name = get_property(g, graph_name);

      if ( g.is_root() )
        out << Traits::name() ;
      else
        out << "subgraph";

      out << " " << g_name << " {" << std::endl;

      typename Graph::const_children_iterator i_child, j_child;

      //print graph/node/edge attributes
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
      typedef typename graph_property<Graph, graph_graph_attribute_t>::type 
        GAttrMap;
      typedef typename graph_property<Graph, graph_vertex_attribute_t>::type
        NAttrMap;
      typedef typename graph_property<Graph, graph_edge_attribute_t>::type
        EAttrMap;
      GAttrMap gam = get_property(g, graph_graph_attribute);
      NAttrMap nam = get_property(g, graph_vertex_attribute);
      EAttrMap eam = get_property(g, graph_edge_attribute);
      graph_attributes_writer<GAttrMap, NAttrMap, EAttrMap> writer(gam, nam, eam);
      writer(out);
#else
      make_graph_attributes_writer(g)(out);
#endif

      //print subgraph
      for ( boost::tie(i_child,j_child) = g.children();
            i_child != j_child; ++i_child )
        write_graphviz_subgraph(out, *i_child, vertex_marker, edge_marker);

      // Print out vertices and edges not in the subgraphs.

      typename boost::graph_traits<Graph>::vertex_iterator i, end;
      typename boost::graph_traits<Graph>::edge_iterator ei, edge_end;

      typename property_map<Graph, vertex_index_t>::const_type 
        indexmap = get(vertex_index, g.root());

      for(boost::tie(i,end) = boost::vertices(g); i != end; ++i) {
        Vertex v = g.local_to_global(*i);
        int pos = get(indexmap, v);
        if ( vertex_marker[pos] ) {
          vertex_marker[pos] = false;
          out << v;
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
          typedef typename property_map<Graph, vertex_attribute_t>::const_type 
            VertexAttributeMap;
          attributes_writer<VertexAttributeMap> vawriter(get(vertex_attribute, 
                                                             g.root()));
          vawriter(out, v);
#else
          make_vertex_attributes_writer(g.root())(out, v);
#endif
          out << ";" << std::endl;
        }
      }

      for (boost::tie(ei, edge_end) = edges(g); ei != edge_end; ++ei) {
        Vertex u = g.local_to_global(source(*ei,g)),
          v = g.local_to_global(target(*ei, g));
        int pos = get(get(edge_index, g.root()), g.local_to_global(*ei));
        if ( edge_marker[pos] ) {
          edge_marker[pos] = false;
          out << u << " " << Traits::delimiter() << " " << v;
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
          typedef typename property_map<Graph, edge_attribute_t>::const_type
            EdgeAttributeMap;
          attributes_writer<EdgeAttributeMap> eawriter(get(edge_attribute, g));
          eawriter(out, *ei);
#else
          make_edge_attributes_writer(g)(out, *ei); //print edge properties
#endif
          out << ";" << std::endl;
        }
      }
      out << "}" << std::endl;
    }
Example #9
0
File: jinit.c Project: HarryR/sanos
void init_jvm_args() {
  JavaVMOption *options;
  struct section *optsect;
  struct section *propsect;
  struct section *cpsect;
  int nopts;
  int n;
  struct property *prop;
  char *buf;
  char *p;
  int len;
  int first;

  cpsect = find_section(cfg, get_property(cfg, cfgname, "classpaths", "java.classpaths"));
  optsect = find_section(cfg, get_property(cfg, cfgname, "options", "java.options"));
  propsect = find_section(cfg, get_property(cfg, cfgname, "properties", "java.properties"));

  nopts = get_section_size(optsect) + get_section_size(propsect) + (cpsect ? 1 : 0);

  options = (JavaVMOption *) malloc(nopts * sizeof(JavaVMOption));
  memset(options, 0, nopts * sizeof(JavaVMOption));

  n = 0;

  if (cpsect) {
    len = strlen("-Djava.class.path=") + 1;
    prop = cpsect->properties;
    while (prop) {
      if (prop->name) len += strlen(prop->name) + 1;
      if (prop->value) len += strlen(prop->value) + 1;
      prop = prop->next;
    }

    buf = (char *) malloc(len);
    strcpy(buf, "-Djava.class.path=");
    p = buf + strlen(buf);
    first = 1;
    prop = cpsect->properties;
    while (prop) {
      if (!first) *p++ = ';';
      first = 0;

      if (prop->name) {
        len = strlen(prop->name);
        memcpy(p, prop->name, len + 1);
        p += len;
      }

      if (prop->value) {
        *p++ = ':';
        len = strlen(prop->value);
        memcpy(p, prop->value, len + 1);
        p += len;
      }

      prop = prop->next;
    }

    options[n++].optionString = buf;
  }

  if (optsect) {
    prop = optsect->properties;
    while (prop) {
      if (prop->value) {
        len = strlen(prop->name) + 1 + strlen(prop->value);
        buf = (char *) malloc(len + 1);
        strcpy(buf, prop->name);
        strcpy(buf + strlen(buf), ":");
        strcpy(buf + strlen(buf), prop->value);
      } else {
        len = strlen(prop->name);
        buf = (char *) malloc(len + 1);
        strcpy(buf, prop->name);
      }

      options[n++].optionString = buf;

      prop = prop->next;
    }
  }

  if (propsect) {
    prop = propsect->properties;
    while (prop) {
      if (prop->value) {
        len = 2 + strlen(prop->name) + 1 + strlen(prop->value);
      } else {
        len = 2 + strlen(prop->name);
      }

      buf = (char *) malloc(len + 1);
      strcpy(buf, "-D");
      strcpy(buf + strlen(buf), prop->name);

      if (prop->value) {
        strcpy(buf + strlen(buf), "=");
        strcpy(buf + strlen(buf), prop->value);
      }

      options[n++].optionString = buf;

      prop = prop->next;
    }
  }

  memset(&args, 0, sizeof(args));
  args.version  = JNI_VERSION_1_2;
  args.nOptions = nopts;
  args.options  = options;
  args.ignoreUnrecognized = JNI_FALSE;
}
Example #10
0
	bool	as_value::to_bool() const
	// Conversion to boolean.
	{
		switch (m_type)
		{
			case STRING:

				// gameswf supports Flash9 only
				return m_string.size() > 0 ? true : false;

				// From Moock
/*				if (get_root()->get_movie_version() >= 7)
				{
					return m_string.size() > 0 ? true : false;
				}

				if (m_string == "false")
				{
					return false;
				}
				else
				if (m_string == "true")
				{
					return true;
				}
				else
				{
					// @@ Moock: "true if the string can
					// be converted to a valid nonzero
					// number".
					//
					// Empty string --> false
					return to_number() != 0.0;
				}*/

			case OBJECT:
				if (m_object)
				{
					return m_object->to_bool();
				}
				return false;

			case PROPERTY:
			{
				as_value val;
				get_property(&val);
				return val.to_bool();
			}

			case NUMBER:
				return m_number != 0;

			case BOOLEAN:
				return m_bool;

			case UNDEFINED:
				return false;

			default:
				assert(0);
		}
		return false;
	}
static int __devinit of_physmap_probe(struct of_device *dev, const struct of_device_id *match)
{
	struct device_node *dp = dev->node;
	struct resource res;
	struct physmap_flash_info *info;
	const char **probe_type;
	const char *of_probe;
	const u32 *width;
	int err;


	if (of_address_to_resource(dp, 0, &res)) {
		dev_err(&dev->dev, "Can't get the flash mapping!\n");
		err = -EINVAL;
		goto err_out;
	}

       	dev_dbg(&dev->dev, "physmap flash device: %.8llx at %.8llx\n",
	    (unsigned long long)res.end - res.start + 1,
	    (unsigned long long)res.start);

	info = kzalloc(sizeof(struct physmap_flash_info), GFP_KERNEL);
	if (info == NULL) {
		err = -ENOMEM;
		goto err_out;
	}
	memset(info, 0, sizeof(*info));

	dev_set_drvdata(&dev->dev, info);

	info->res = request_mem_region(res.start, res.end - res.start + 1,
			dev->dev.bus_id);
	if (info->res == NULL) {
		dev_err(&dev->dev, "Could not reserve memory region\n");
		err = -ENOMEM;
		goto err_out;
	}

	width = get_property(dp, "bank-width", NULL);
	if (width == NULL) {
		dev_err(&dev->dev, "Can't get the flash bank width!\n");
		err = -EINVAL;
		goto err_out;
	}

	info->map.name = dev->dev.bus_id;
	info->map.phys = res.start;
	info->map.size = res.end - res.start + 1;
	info->map.bankwidth = *width;

	info->map.virt = ioremap(info->map.phys, info->map.size);
	if (info->map.virt == NULL) {
		dev_err(&dev->dev, "Failed to ioremap flash region\n");
		err = EIO;
		goto err_out;
	}

	simple_map_init(&info->map);

	of_probe = get_property(dp, "probe-type", NULL);
	if (of_probe == NULL) {
		probe_type = rom_probe_types;
		for (; info->mtd == NULL && *probe_type != NULL; probe_type++)
			info->mtd = do_map_probe(*probe_type, &info->map);
	} else if (!strcmp(of_probe, "CFI"))
		info->mtd = do_map_probe("cfi_probe", &info->map);
	else if (!strcmp(of_probe, "JEDEC"))
		info->mtd = do_map_probe("jedec_probe", &info->map);
	else {
 		if (strcmp(of_probe, "ROM"))
			dev_dbg(&dev->dev, "map_probe: don't know probe type "
			"'%s', mapping as rom\n");
		info->mtd = do_map_probe("mtd_rom", &info->map);
	}
	if (info->mtd == NULL) {
		dev_err(&dev->dev, "map_probe failed\n");
		err = -ENXIO;
		goto err_out;
	}
	info->mtd->owner = THIS_MODULE;

#ifdef CONFIG_MTD_PARTITIONS
	err = parse_mtd_partitions(info->mtd, part_probe_types, &info->parts, 0);
	if (err > 0) {
		add_mtd_partitions(info->mtd, info->parts, err);
	} else if ((err = parse_flash_partitions(dp, &info->parts)) > 0) {
		dev_info(&dev->dev, "Using OF partition information\n");
		add_mtd_partitions(info->mtd, info->parts, err);
		info->nr_parts = err;
	} else
#endif

	add_mtd_device(info->mtd);
	return 0;

err_out:
	of_physmap_remove(dev);
	return err;

	return 0;


}
Example #12
0
	const tu_string&	as_value::to_tu_string() const
	// Conversion to const tu_string&.
	{
		switch (m_type)
		{
			case STRING:
				// don't need to do anything
				break;

			case UNDEFINED:
			{
				// gameswf supports Flash9 only
				m_string = "undefined";

				// Behavior depends on file version.  In
				// version 7+, it's "undefined", in versions
				// 6-, it's "".
//				if (version <= 6)
//				{
//					m_string = "";
//				}
//				else
//				{
//					m_string = "undefined";
//				}
				break;
			}

			case BOOLEAN:
				m_string = m_bool ? "true" : "false";
				break;

			case NUMBER:
				// @@ Moock says if value is a NAN, then result is "NaN"
				// INF goes to "Infinity"
				// -INF goes to "-Infinity"
				if (isnan(m_number))
				{
					m_string = "NaN";
				} 
				else
				{
					char buffer[50];
					snprintf(buffer, 50, "%.14g", m_number);
					m_string = buffer;
				}
				break;

			case OBJECT:
				// Moock says, "the value that results from
				// calling toString() on the object".
				//
				// The default toString() returns "[object
				// Object]" but may be customized.
				if (m_object == NULL)
				{
					m_string = "null";
				}
				else
				{
					m_string = m_object->to_string();
				}
				break;
	
			case PROPERTY:
			{
				as_value val;
				get_property(&val);
				m_string = val.to_tu_string();
				break;
			}

			default:
				assert(0);
		}
		return m_string;
	}
Example #13
0
File: area.c Project: caomw/grass
int display_area(struct Map_info *Map, struct cat_list *Clist, const struct Cell_head *window,
		 const struct color_rgb *bcolor, const struct color_rgb *fcolor, int chcat,
		 int id_flag, int cats_color_flag, 
		 int default_width, double width_scale,
		 struct Colors *zcolors,
		 dbCatValArray *cvarr_rgb, struct Colors *colors,
		 dbCatValArray *cvarr_width, int nrec_width)
{
    int num, area, isle, n_isles, n_points;
    double xl, yl;
    struct line_pnts *Points, * APoints, **IPoints;
    struct line_cats *Cats;
    int n_ipoints_alloc;
    int cat, centroid;
    int red, grn, blu;

    int i, custom_rgb, found;
    int width;
    struct bound_box box;
    
    if (Vect_level(Map) < 2) {
	G_warning(_("Unable to display areas, topology not available. "
		    "Please try to rebuild topology using "
		    "v.build or v.build.all."));
	return 1;
    }

    G_debug(1, "display areas:");
    
    centroid = 0;
    Points = Vect_new_line_struct();
    APoints = Vect_new_line_struct();
    n_ipoints_alloc = 10;
    IPoints = (struct line_pnts **)G_malloc(n_ipoints_alloc * sizeof(struct line_pnts *));
    for (i = 0; i < n_ipoints_alloc; i++) {
	IPoints[i] = Vect_new_line_struct();
    }
    Cats = Vect_new_cats_struct();
    
    num = Vect_get_num_areas(Map);
    G_debug(2, "\tn_areas = %d", num);

    for (area = 1; area <= num; area++) {
	G_debug(3, "\tarea = %d", area);

	if (!Vect_area_alive(Map, area))
	    continue;

	centroid = Vect_get_area_centroid(Map, area);
	if (!centroid) {
	    continue;
	}

	/* Check box */
	Vect_get_area_box(Map, area, &box);
	if (box.N < window->south || box.S > window->north ||
	    box.E < window->west || box.W > window->east) {
	    if (window->proj != PROJECTION_LL)
		continue;
	    else { /* out of bounds for -180 to 180, try 0 to 360 as well */
		if (box.N < window->south || box.S > window->north)
		    continue;
		if (box.E + 360 < window->west || box.W + 360 > window->east)
		    continue;
	    }
	}

	custom_rgb = FALSE;
		
	found = FALSE;
	if (chcat) {		
	    if (id_flag) {
		if (!(Vect_cat_in_cat_list(area, Clist)))
		    continue;
	    }
	    else {
		G_debug(3, "centroid = %d", centroid);
		if (centroid < 1)
		    continue;
		Vect_read_line(Map, Points, Cats, centroid);

		for (i = 0; i < Cats->n_cats; i++) {
		    G_debug(3, "  centroid = %d, field = %d, cat = %d",
			    centroid, Cats->field[i], Cats->cat[i]);

		    if (Cats->field[i] == Clist->field &&
			Vect_cat_in_cat_list(Cats->cat[i], Clist)) {
			found = TRUE;
			break;
		    }
		}
		
		if (!found)
		    continue;
	    }
	}
	else if (Clist->field > 0) {
	    found = FALSE;
	    G_debug(3, "\tcentroid = %d", centroid);
	    if (centroid < 1)
		continue;
	    Vect_read_line(Map, NULL, Cats, centroid);

	    for (i = 0; i < Cats->n_cats; i++) {
		G_debug(3, "\tcentroid = %d, field = %d, cat = %d", centroid,
			Cats->field[i], Cats->cat[i]);
		if (Cats->field[i] == Clist->field) {
		    found = TRUE;
		    break;
		}
	    }
	    
	    /* lines with no category will be displayed */
	    if (Cats->n_cats > 0 && !found)
		continue;
	}

	/* fill */
	Vect_get_area_points(Map, area, APoints);
	G_debug(3, "\tn_points = %d", APoints->n_points);
	if (APoints->n_points < 3) {
	    G_warning(_("Invalid area %d skipped (not enough points)"), area);
	    continue;
	}
	Vect_reset_line(Points);
	Vect_append_points(Points, APoints, GV_FORWARD);

	n_points = Points->n_points;
	xl = Points->x[n_points - 1];
	yl = Points->y[n_points - 1];
	n_isles = Vect_get_area_num_isles(Map, area);
	if (n_isles >= n_ipoints_alloc) {
	    IPoints = (struct line_pnts **)G_realloc(IPoints, (n_isles + 10) * sizeof(struct line_pnts *));
	    for (i = n_ipoints_alloc; i < n_isles + 10; i++) {
		IPoints[i] = Vect_new_line_struct();
	    }
	    n_ipoints_alloc = n_isles + 10;
	}
	for (i = 0; i < n_isles; i++) {
	    isle = Vect_get_area_isle(Map, area, i);
	    Vect_get_isle_points(Map, isle, IPoints[i]);
	    Vect_append_points(Points, IPoints[i], GV_FORWARD);
	    Vect_append_point(Points, xl, yl, 0.0);	/* ??? */
	}

	cat = Vect_get_area_cat(Map, area,
				(Clist->field > 0 ? Clist->field :
				 (Cats->n_cats > 0 ? Cats->field[0] : 1)));

	if (!centroid && cat == -1) {
	    continue;
	}

	/* z height colors */
	if (zcolors) {
	    if (Rast_get_d_color(&Points->z[0], &red, &grn, &blu, zcolors) == 1)
		custom_rgb = TRUE;
	    else
		custom_rgb = FALSE;
	}

        /* custom colors */
	if (colors || cvarr_rgb) {
	    custom_rgb = get_table_color(cat, area, colors, cvarr_rgb,
					 &red, &grn, &blu);
	}
	
	/* random colors */
	if (cats_color_flag) {
	    custom_rgb = get_cat_color(area, Cats, Clist,
				       &red, &grn, &blu);
	}
	
	/* line width */
	if (nrec_width) {
	    width = (int) get_property(cat, area, cvarr_width,
				       (double) width_scale,
				       (double) default_width);
	    
	    D_line_width(width);
	}
	
	if (fcolor || zcolors) {
	    if (!cvarr_rgb && !cats_color_flag && !zcolors && !colors) {
		D_RGB_color(fcolor->r, fcolor->g, fcolor->b);
		D_polygon_abs(Points->x, Points->y, Points->n_points);
	    }
	    else {
		if (custom_rgb) {
		    D_RGB_color((unsigned char)red, (unsigned char)grn,
				(unsigned char)blu);
		}
		else {
		    D_RGB_color(fcolor->r, fcolor->g, fcolor->b);
		}
		if (cat >= 0) {
		    D_polygon_abs(Points->x, Points->y, Points->n_points);
		}
	    }
	}

	/* boundary */
	if (bcolor) {
	    if (custom_rgb) {
		D_RGB_color((unsigned char)red, (unsigned char)grn,
			    (unsigned char)blu);
	    }
	    else {
		D_RGB_color(bcolor->r, bcolor->g, bcolor->b);
	    }
	    /* use different user defined render methods */
	    D_polyline_abs(APoints->x, APoints->y, APoints->n_points);
	    for (i = 0; i < n_isles; i++) {
		/* use different user defined render methods */
		D_polyline_abs(IPoints[i]->x, IPoints[i]->y, IPoints[i]->n_points);
	    }
	}
    }

    if ((colors || cvarr_rgb) && get_num_color_rules_skipped() > 0)
        G_warning(_n("%d invalid color rule for areas skipped", 
                "%d invalid color rules for areas skipped", 
                get_num_color_rules_skipped()), 
                get_num_color_rules_skipped());

    Vect_destroy_line_struct(Points);
    Vect_destroy_line_struct(APoints);
    for (i = 0; i < n_ipoints_alloc; i++) {
	Vect_destroy_line_struct(IPoints[i]);
    }
    G_free(IPoints);
    Vect_destroy_cats_struct(Cats);

    return 0;
}
Example #14
0
static int
create_iface(struct device_node *np, struct device *dev)
{
	unsigned long steps;
	unsigned bsteps, tsize, i, nchan, addroffset;
	struct keywest_iface* iface;
	u32 *psteps, *prate;
	int rc;

	if (pmac_low_i2c_lock(np))
		return -ENODEV;

	psteps = (u32 *)get_property(np, "AAPL,address-step", NULL);
	steps = psteps ? (*psteps) : 0x10;

	/* Hrm... maybe we can be smarter here */
	for (bsteps = 0; (steps & 0x01) == 0; bsteps++)
		steps >>= 1;

	if (np->parent->name[0] == 'u') {
		nchan = 2;
		addroffset = 3;
	} else {
		addroffset = 0;
		nchan = 1;
	}

	tsize = sizeof(struct keywest_iface) +
		(sizeof(struct keywest_chan) + 4) * nchan;
	iface = (struct keywest_iface *) kmalloc(tsize, GFP_KERNEL);
	if (iface == NULL) {
		printk(KERN_ERR "i2c-keywest: can't allocate inteface !\n");
		pmac_low_i2c_unlock(np);
		return -ENOMEM;
	}
	memset(iface, 0, tsize);
	spin_lock_init(&iface->lock);
	init_completion(&iface->complete);
	iface->node = of_node_get(np);
	iface->bsteps = bsteps;
	iface->chan_count = nchan;
	iface->state = state_idle;
	iface->irq = np->intrs[0].line;
	iface->channels = (struct keywest_chan *)
		(((unsigned long)(iface + 1) + 3UL) & ~3UL);
	iface->base = ioremap(np->addrs[0].address + addroffset,
						np->addrs[0].size);
	if (!iface->base) {
		printk(KERN_ERR "i2c-keywest: can't map inteface !\n");
		kfree(iface);
		pmac_low_i2c_unlock(np);
		return -ENOMEM;
	}

#ifndef POLLED_MODE
	init_timer(&iface->timeout_timer);
	iface->timeout_timer.function = keywest_timeout;
	iface->timeout_timer.data = (unsigned long)iface;
#endif

	/* Select interface rate */
	iface->cur_mode = KW_I2C_MODE_100KHZ;
	prate = (u32 *)get_property(np, "AAPL,i2c-rate", NULL);
	if (prate) switch(*prate) {
	case 100:
		iface->cur_mode = KW_I2C_MODE_100KHZ;
		break;
	case 50:
		iface->cur_mode = KW_I2C_MODE_50KHZ;
		break;
	case 25:
		iface->cur_mode = KW_I2C_MODE_25KHZ;
		break;
	default:
		printk(KERN_WARNING "i2c-keywest: unknown rate %ldKhz, using 100KHz\n",
		       (long)*prate);
	}
	
	/* Select standard mode by default */
	iface->cur_mode |= KW_I2C_MODE_STANDARD;
	
	/* Write mode */
	write_reg(reg_mode, iface->cur_mode);
	
	/* Switch interrupts off & clear them*/
	write_reg(reg_ier, 0x00);
	write_reg(reg_isr, KW_I2C_IRQ_MASK);

#ifndef POLLED_MODE
	/* Request chip interrupt */	
	rc = request_irq(iface->irq, keywest_irq, SA_INTERRUPT, "keywest i2c", iface);
	if (rc) {
		printk(KERN_ERR "i2c-keywest: can't get IRQ %d !\n", iface->irq);
		iounmap(iface->base);
		kfree(iface);
		pmac_low_i2c_unlock(np);
		return -ENODEV;
	}
#endif /* POLLED_MODE */

	pmac_low_i2c_unlock(np);
	dev_set_drvdata(dev, iface);
	
	for (i=0; i<nchan; i++) {
		struct keywest_chan* chan = &iface->channels[i];
		u8 addr;
		
		sprintf(chan->adapter.name, "%s %d", np->parent->name, i);
		chan->iface = iface;
		chan->chan_no = i;
		chan->adapter.id = I2C_ALGO_SMBUS;
		chan->adapter.algo = &keywest_algorithm;
		chan->adapter.algo_data = NULL;
		chan->adapter.client_register = NULL;
		chan->adapter.client_unregister = NULL;
		i2c_set_adapdata(&chan->adapter, chan);
		chan->adapter.dev.parent = dev;

		rc = i2c_add_adapter(&chan->adapter);
		if (rc) {
			printk("i2c-keywest.c: Adapter %s registration failed\n",
				chan->adapter.name);
			i2c_set_adapdata(&chan->adapter, NULL);
		}
		if (probe) {
			printk("Probe: ");
			for (addr = 0x00; addr <= 0x7f; addr++) {
				if (i2c_smbus_xfer(&chan->adapter,addr,
				    0,0,0,I2C_SMBUS_QUICK,NULL) >= 0)
					printk("%02x ", addr);
			}
			printk("\n");
		}
	}

	printk(KERN_INFO "Found KeyWest i2c on \"%s\", %d channel%s, stepping: %d bits\n",
		np->parent->name, nchan, nchan > 1 ? "s" : "", bsteps);
		
	return 0;
}
Example #15
0
int
main (int argc, char **argv)
{
//  int i = 0;
//  char buf[MAXBUFSIZE];
  int c = 0, option_index = 0;
  int x = 0, y = 0;
  struct option long_only_options[ARGS_MAX];
  int result = 0;
//  const char *p = NULL; 
  const st_property_t props[] =
    {
      {
        "ansi_color", "1",
        "use ANSI colors in output? (1=yes; 0=no)"
      },
      {
        "default_cmdline", "",
        "will be used when quh is started w/o args"
      },
      {
        "settings", "100",
        "internal settings like volume, etc."
      },
#if 0
      {
        "quh_configdir",
        PROPERTY_MODE_DIR ("quh"),
        "directory with additional config files"
      },
#endif
      {NULL, NULL, NULL}
    };

  memset (&quh, 0, sizeof (st_quh_t));

  // defaults
  quh.pid = 1;
  tmpnam3 (quh.tmp_file, 0);
  set_suffix (quh.tmp_file, ".wav");

  if(!(quh.o = cache_open (MAXBUFSIZE, CACHE_MEM|CACHE_LIFO)))
    {
      fprintf (stderr, "ERROR: Could not malloc %d bytes\n", MAXBUFSIZE);
      return -1;
    }

  realpath2 (PROPERTY_HOME_RC ("quh"), quh.configfile);

  result = property_check (quh.configfile, QUH_CONFIG_VERSION, 1);
  if (result == 1) // update needed
    result = set_property_array (quh.configfile, props);
  if (result == -1) // property_check() or update failed
    return -1;

  signal (SIGINT, quh_signal_handler);
  signal (SIGTERM, quh_signal_handler);

  atexit (quh_exit);

  quh.ansi_color = get_property_int (quh.configfile, "ansi_color");
  quh.settings = get_property_int (quh.configfile, "settings");

  quh.argc = argc;
  quh.argv = argv;

#if 0
  // memorize cmdline
  if (quh.argc > 2)
    { 
      for (; quh.argv[i] && i < quh.argc; i++)
        sprintf (strchr (buf, 0), "%s ", quh.argv[i]);

      set_property (quh.configfile, "default_cmdline", buf,
                    "will be used when quh is started w/o args");
    }
  else
    {
      p = get_property (quh.configfile, "default_cmdline", PROPERTY_MODE_TEXT);

      if (p)
        { 
          strncpy (buf, p, MAXBUFSIZE)[MAXBUFSIZE - 1] = 0;
          quh.argc = strarg (quh.argv, buf, " ", QUH_MAX_ARGS);
        }
    }
#endif

  // set default filter chain
  filters = 0;
  quh.filter_id[filters++] = QUH_CACHE_PASS;
  quh.filter_id[filters++] = QUH_CONSOLE_PASS;
#ifdef  USE_ID3
//  quh.filter_id[filters++] = QUH_ID3_IN;
#endif
//  quh.filter_id[filters++] = QUH_CDDB_IN;
#ifdef  USE_OSS
  quh.filter_id[filters++] = QUH_OSS_OUT;
#elif   defined USE_SDL
  quh.filter_id[filters++] = QUH_SDL_OUT;
#endif

  // convert (st_getopt2_t **) to (st_getopt2_t *)
  memset (&options, 0, sizeof (st_getopt2_t) * QUH_MAX_ARGS);
  for (c = x = 0; option[x]; x++)
    for (y = 0; option[x][y].name || option[x][y].help; y++)
      if (c < QUH_MAX_ARGS)
        {
          memcpy (&options[c], &option[x][y], sizeof (st_getopt2_t));
          c++;
        }

#if 0
  for (x = 0; quh_decode_usage[x]; x++)
    if (c < QUH_MAX_ARGS)
      {
        memcpy (&options[c], quh_decode_usage[x], sizeof (st_getopt2_t));
        c++;
      }
#endif

  for (x = 0; quh_filter_usage[x]; x++)
    if (c < QUH_MAX_ARGS)
      {
        memcpy (&options[c], quh_filter_usage[x], sizeof (st_getopt2_t));
        c++;
      }

  for (x = 0; option2[x]; x++)
    for (y = 0; option2[x][y].name || option2[x][y].help; y++)
      if (c < QUH_MAX_ARGS)
        {
          memcpy (&options[c], &option2[x][y], sizeof (st_getopt2_t));
          c++;
        }

  getopt2_long_only (long_only_options, options, ARGS_MAX);

#if 0
  // if no options or filenames were specified we use a default cmdline
  if (argc < 2) // || !optind)
    {
      p = get_property (quh.configfile, "default_cmdline", PROPERTY_MODE_TEXT);
      if (p)
        {
          strncpy (quh.cmdline, p, ARGS_MAX)[ARGS_MAX - 1] = 0;
          quh.argc = strarg (quh.argv, quh.cmdline, " ", QUH_MAX_ARGS);
        }
    }
  else // store cmdline
    {
      strcpy (quh.cmdline, argv[0]);
      for (x = 1; x < argc; x++)
        sprintf (strchr (quh.cmdline, 0), " \"%s\"", quh.argv[x]);
      set_property (quh.configfile, "default_cmdline", quh.cmdline, NULL);
    }

  for (x = 0; x < quh.argc; x++)
    printf ("quh.argv[%d] == %s\n", x, quh.argv[x]);
  fflush (stdout);
#endif

  while ((c = getopt_long_only (quh.argc, quh.argv, "", long_only_options, &option_index)) != -1)
    quh_opts (c);

//  if (quh.verbose)
  if (!quh.quiet)
    fputs ("Quh " QUH_VERSION_S " 'Having ears makes sense again' 2005-2006 by NoisyB\n"
           "This may be freely redistributed under the terms of the GNU Public License\n\n", stdout);

  if (quh.argc < 2) // || !optind)
    {
      getopt2_usage (options);
      return -1;
    }

#warning files?
#if 0
  if (!getfile (quh.argc, quh.argv, quh_set_fname,
                (GETFILE_FILES_ONLY | (quh.flags & QUH_RECURSIVE ? GETFILE_RECURSIVE : 0)))) // recursively?
    {
      if (!quh.quiet)
        getopt2_usage (options);
      return -1;
    }
#endif

  if (!quh.filter_id[0])
    {
      fputs ("ERROR: you haven't specified any filters\n", stderr);
      fflush (stderr);
      return -1;
    }

  if (!quh.files)
    {
      fputs ("ERROR: you haven't specified any files to play\n", stderr);
      fflush (stderr);
      return -1;
    }

  if (!(quh.filter_chain = filter_malloc_chain (quh_filter)))
    {
      fputs ("ERROR: filter_malloc_chain() failed\n", stderr);
      fflush (stderr);
      return -1;
    }

  if (filter_init (quh.filter_chain, NULL, NULL) == -1)
    {
      fputs ("ERROR: filter_init() failed\n", stderr);
      fflush (stderr);
      return -1;
    }

  quh_play ();

  return 0;
}
Example #16
0
/**
 * get_dynamic_reconfig_lmbs
 * @brief Retrieve lmbs from OF device tree located in the ibm,dynamic-memory
 * property.
 *
 * @param lmb_list pointer to lmb list head to populate
 * @returns 0 on success, !0 on failure
 */
int
get_dynamic_reconfig_lmbs(struct lmb_list_head *lmb_list)
{
	struct drconf_mem *drmem;
	uint64_t lmb_sz;
	int i, num_entries;
	int rc = 0;

	rc = get_property(DYNAMIC_RECONFIG_MEM, "ibm,lmb-size",
			  &lmb_sz, sizeof(lmb_sz));

	/* convert for LE systems */
	lmb_sz = be64toh(lmb_sz);

	if (rc) {
		say(DEBUG, "Could not retrieve drconf LMB size\n");
		return rc;
	}

	lmb_list->drconf_buf_sz = get_property_size(DYNAMIC_RECONFIG_MEM,
						   "ibm,dynamic-memory");
	lmb_list->drconf_buf = zalloc(lmb_list->drconf_buf_sz);
	if (lmb_list->drconf_buf == NULL) {
		say(DEBUG, "Could not allocate buffer to get dynamic "
		    "reconfigurable memory\n");
		return -1;
	}

	rc = get_property(DYNAMIC_RECONFIG_MEM, "ibm,dynamic-memory",
			  lmb_list->drconf_buf, lmb_list->drconf_buf_sz);
	if (rc) {
		say(DEBUG, "Could not retrieve dynamic reconfigurable memory "
		    "property\n");
		return -1;
	}

	/* The first integer of the buffer is the number of entries */
	num_entries = *(int *)lmb_list->drconf_buf;

	/* convert for LE systems */
	num_entries = be32toh(num_entries);

	/* Followed by the actual entries */
	drmem = (struct drconf_mem *)
				(lmb_list->drconf_buf + sizeof(num_entries));
	for (i = 0; i < num_entries; i++) {
		struct dr_node *lmb;

		lmb = lmb_list_add(be32toh(drmem->drc_index), lmb_list);
		if (lmb == NULL) {
			say(DEBUG, "Could not find LMB with drc-index of %x\n",
			    drmem->drc_index);
			rc = -1;
			break;
		}

		sprintf(lmb->ofdt_path, DYNAMIC_RECONFIG_MEM);
		lmb->lmb_size = lmb_sz;
		lmb->lmb_address = be64toh(drmem->address);
		lmb->lmb_aa_index = be32toh(drmem->assoc_index);

		if (be32toh(drmem->flags) & DRMEM_ASSIGNED) {
			lmb->is_owned = 1;

			/* find the associated sysfs memory blocks */
			rc = get_mem_scns(lmb);
			if (rc)
				break;
		}

		lmb_list->lmbs_found++;
		drmem++; /* trust your compiler */
	}

	say(INFO, "Found %d LMBs currently allocated\n", lmb_list->lmbs_found);
	return rc;
}
Example #17
0
static void __init pseries_mpic_init_IRQ(void)
{
	struct device_node *np, *old, *cascade = NULL;
        const unsigned int *addrp;
	unsigned long intack = 0;
	const unsigned int *opprop;
	unsigned long openpic_addr = 0;
	unsigned int cascade_irq;
	int naddr, n, i, opplen;
	struct mpic *mpic;

	np = of_find_node_by_path("/");
	naddr = prom_n_addr_cells(np);
	opprop = get_property(np, "platform-open-pic", &opplen);
	if (opprop != 0) {
		openpic_addr = of_read_number(opprop, naddr);
		printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
	}
	of_node_put(np);

	BUG_ON(openpic_addr == 0);

	/* Setup the openpic driver */
	mpic = mpic_alloc(pSeries_mpic_node, openpic_addr,
			  MPIC_PRIMARY,
			  16, 250, /* isu size, irq count */
			  " MPIC     ");
	BUG_ON(mpic == NULL);

	/* Add ISUs */
	opplen /= sizeof(u32);
	for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
		unsigned long isuaddr = of_read_number(opprop + i, naddr);
		mpic_assign_isu(mpic, n, isuaddr);
	}

	/* All ISUs are setup, complete initialization */
	mpic_init(mpic);

	/* Look for cascade */
	for_each_node_by_type(np, "interrupt-controller")
		if (device_is_compatible(np, "chrp,iic")) {
			cascade = np;
			break;
		}
	if (cascade == NULL)
		return;

	cascade_irq = irq_of_parse_and_map(cascade, 0);
	if (cascade == NO_IRQ) {
		printk(KERN_ERR "mpic: failed to map cascade interrupt");
		return;
	}

	/* Check ACK type */
	for (old = of_node_get(cascade); old != NULL ; old = np) {
		np = of_get_parent(old);
		of_node_put(old);
		if (np == NULL)
			break;
		if (strcmp(np->name, "pci") != 0)
			continue;
		addrp = get_property(np, "8259-interrupt-acknowledge",
					    NULL);
		if (addrp == NULL)
			continue;
		naddr = prom_n_addr_cells(np);
		intack = addrp[naddr-1];
		if (naddr > 1)
			intack |= ((unsigned long)addrp[naddr-2]) << 32;
	}
	if (intack)
		printk(KERN_DEBUG "mpic: PCI 8259 intack at 0x%016lx\n",
		       intack);
	i8259_init(cascade, intack);
	of_node_put(cascade);
	set_irq_chained_handler(cascade_irq, pseries_8259_cascade);
}
Example #18
0
 int64_t chain_interface::get_required_confirmations()const
 {
    return get_property( confirmation_requirement ).as_int64();
 }
Example #19
0
 graph_bundled& operator[](graph_bundle_t)
 { return get_property(*this); }
Example #20
0
/**
 * vio_get_attribute: - get attribute for virtual device
 * @vdev:	The vio device to get property.
 * @which:	The property/attribute to be extracted.
 * @length:	Pointer to length of returned data size (unused if NULL).
 *
 * Calls prom.c's get_property() to return the value of the
 * attribute specified by @which
*/
const void *vio_get_attribute(struct vio_dev *vdev, char *which, int *length)
{
	return get_property(vdev->dev.platform_data, which, length);
}
static int __init add_legacy_pci_port(struct device_node *np,
				      struct device_node *pci_dev)
{
	u64 addr, base;
	const u32 *addrp;
	unsigned int flags;
	int iotype, index = -1, lindex = 0;

	DBG(" -> add_legacy_pci_port(%s)\n", np->full_name);

	/* We only support ports that have a clock frequency properly
	 * encoded in the device-tree (that is have an fcode). Anything
	 * else can't be used that early and will be normally probed by
	 * the generic 8250_pci driver later on. The reason is that 8250
	 * compatible UARTs on PCI need all sort of quirks (port offsets
	 * etc...) that this code doesn't know about
	 */
	if (get_property(np, "clock-frequency", NULL) == NULL)
		return -1;

	/* Get the PCI address. Assume BAR 0 */
	addrp = of_get_pci_address(pci_dev, 0, NULL, &flags);
	if (addrp == NULL)
		return -1;

	/* We only support BAR 0 for now */
	iotype = (flags & IORESOURCE_MEM) ? UPIO_MEM : UPIO_PORT;
	addr = of_translate_address(pci_dev, addrp);
	if (addr == OF_BAD_ADDR)
		return -1;

	/* Set the IO base to the same as the translated address for MMIO,
	 * or to the domain local IO base for PIO (it will be fixed up later)
	 */
	if (iotype == UPIO_MEM)
		base = addr;
	else
		base = addrp[2];

	/* Try to guess an index... If we have subdevices of the pci dev,
	 * we get to their "reg" property
	 */
	if (np != pci_dev) {
		const u32 *reg = get_property(np, "reg", NULL);
		if (reg && (*reg < 4))
			index = lindex = *reg;
	}

	/* Local index means it's the Nth port in the PCI chip. Unfortunately
	 * the offset to add here is device specific. We know about those
	 * EXAR ports and we default to the most common case. If your UART
	 * doesn't work for these settings, you'll have to add your own special
	 * cases here
	 */
	if (device_is_compatible(pci_dev, "pci13a8,152") ||
	    device_is_compatible(pci_dev, "pci13a8,154") ||
	    device_is_compatible(pci_dev, "pci13a8,158")) {
		addr += 0x200 * lindex;
		base += 0x200 * lindex;
	} else {
		addr += 8 * lindex;
		base += 8 * lindex;
	}

	/* Add port, irq will be dealt with later. We passed a translated
	 * IO port value. It will be fixed up later along with the irq
	 */
	return add_legacy_port(np, index, iotype, base, addr, NO_IRQ,
			       UPF_BOOT_AUTOCONF, np != pci_dev);
}
Example #22
0
int __pmac
pmac_show_cpuinfo(struct seq_file *m)
{
	struct device_node *np;
	char *pp;
	int plen;

	/* find motherboard type */
	seq_printf(m, "machine\t\t: ");
	np = find_devices("device-tree");
	if (np != NULL) {
		pp = (char *) get_property(np, "model", NULL);
		if (pp != NULL)
			seq_printf(m, "%s\n", pp);
		else
			seq_printf(m, "PowerMac\n");
		pp = (char *) get_property(np, "compatible", &plen);
		if (pp != NULL) {
			seq_printf(m, "motherboard\t:");
			while (plen > 0) {
				int l = strlen(pp) + 1;
				seq_printf(m, " %s", pp);
				plen -= l;
				pp += l;
			}
			seq_printf(m, "\n");
		}
	} else
		seq_printf(m, "PowerMac\n");

	/* find l2 cache info */
	np = find_devices("l2-cache");
	if (np == 0)
		np = find_type_devices("cache");
	if (np != 0) {
		unsigned int *ic = (unsigned int *)
			get_property(np, "i-cache-size", NULL);
		unsigned int *dc = (unsigned int *)
			get_property(np, "d-cache-size", NULL);
		seq_printf(m, "L2 cache\t:");
		has_l2cache = 1;
		if (get_property(np, "cache-unified", NULL) != 0 && dc) {
			seq_printf(m, " %dK unified", *dc / 1024);
		} else {
			if (ic)
				seq_printf(m, " %dK instruction", *ic / 1024);
			if (dc)
				seq_printf(m, "%s %dK data",
					   (ic? " +": ""), *dc / 1024);
		}
		pp = get_property(np, "ram-type", NULL);
		if (pp)
			seq_printf(m, " %s", pp);
		seq_printf(m, "\n");
	}

	/* find ram info */
	np = find_devices("memory");
	if (np != 0) {
		int n;
		struct reg_property *reg = (struct reg_property *)
			get_property(np, "reg", &n);
		
		if (reg != 0) {
			unsigned long total = 0;

			for (n /= sizeof(struct reg_property); n > 0; --n)
				total += (reg++)->size;
			seq_printf(m, "memory\t\t: %luMB\n", total >> 20);
		}
static int __init add_legacy_port(struct device_node *np, int want_index,
				  int iotype, phys_addr_t base,
				  phys_addr_t taddr, unsigned long irq,
				  upf_t flags, int irq_check_parent)
{
	const u32 *clk, *spd;
	u32 clock = BASE_BAUD * 16;
	int index;

	/* get clock freq. if present */
	clk = get_property(np, "clock-frequency", NULL);
	if (clk && *clk)
		clock = *clk;

	/* get default speed if present */
	spd = get_property(np, "current-speed", NULL);

	/* If we have a location index, then try to use it */
	if (want_index >= 0 && want_index < MAX_LEGACY_SERIAL_PORTS)
		index = want_index;
	else
		index = legacy_serial_count;

	/* if our index is still out of range, that mean that
	 * array is full, we could scan for a free slot but that
	 * make little sense to bother, just skip the port
	 */
	if (index >= MAX_LEGACY_SERIAL_PORTS)
		return -1;
	if (index >= legacy_serial_count)
		legacy_serial_count = index + 1;

	/* Check if there is a port who already claimed our slot */
	if (legacy_serial_infos[index].np != 0) {
		/* if we still have some room, move it, else override */
		if (legacy_serial_count < MAX_LEGACY_SERIAL_PORTS) {
			printk(KERN_DEBUG "Moved legacy port %d -> %d\n",
			       index, legacy_serial_count);
			legacy_serial_ports[legacy_serial_count] =
				legacy_serial_ports[index];
			legacy_serial_infos[legacy_serial_count] =
				legacy_serial_infos[index];
			legacy_serial_count++;
		} else {
			printk(KERN_DEBUG "Replacing legacy port %d\n", index);
		}
	}

	/* Now fill the entry */
	memset(&legacy_serial_ports[index], 0,
	       sizeof(struct plat_serial8250_port));
	if (iotype == UPIO_PORT)
		legacy_serial_ports[index].iobase = base;
	else
		legacy_serial_ports[index].mapbase = base;
	legacy_serial_ports[index].iotype = iotype;
	legacy_serial_ports[index].uartclk = clock;
	legacy_serial_ports[index].irq = irq;
	legacy_serial_ports[index].flags = flags;
	legacy_serial_infos[index].taddr = taddr;
	legacy_serial_infos[index].np = of_node_get(np);
	legacy_serial_infos[index].clock = clock;
	legacy_serial_infos[index].speed = spd ? *spd : 0;
	legacy_serial_infos[index].irq_check_parent = irq_check_parent;

	printk(KERN_DEBUG "Found legacy serial port %d for %s\n",
	       index, np->full_name);
	printk(KERN_DEBUG "  %s=%llx, taddr=%llx, irq=%lx, clk=%d, speed=%d\n",
	       (iotype == UPIO_PORT) ? "port" : "mem",
	       (unsigned long long)base, (unsigned long long)taddr, irq,
	       legacy_serial_ports[index].uartclk,
	       legacy_serial_infos[index].speed);

	return index;
}
Example #24
0
pword *
set_modular_property(dident functor, int property_name, dident module, type mod_tag, int flag, int *err_ref)
{
    register property	*p, *head;
    module_item		*pm;

    if (flag == LOCAL_PROP && IsLocked(module)
	&& !IsModuleTag(module, mod_tag))
    {
	Property_Error(err_ref, LOCKED);
    }

    /* get pointer to property list from atom */
    a_mutex_lock(&PropListLock);
    head = p = DidProperties(functor);

    while (p && p->name != property_name)	/* find the right one	*/
    {
	head = p;
	p = p->next_prop;
    }

    if (!p)					/* no such property yet	*/
    {
	p = (property *) hg_alloc_size(sizeof(property));
	p->name = property_name;
	p->next_prop = (property *) NULL;
	p->next_mod = p;
	p->module = D_UNKNOWN;
	if (head)
	    head->next_prop = p;
	else
	    DidProperties(functor) = p;
    }

    if (flag == GLOBAL_PROP)
    {
	if (p->module == D_UNKNOWN)
	{
	    p->module = module;			/* fill unused descriptor */
	    p->property_value.tag.kernel = TEND;
	    a_mutex_unlock(&PropListLock);
	    return &p->property_value;
	}
	else
	{
	    a_mutex_unlock(&PropListLock);
	    Property_Error(err_ref, PERROR)/* global exists already */
	}
    }

    /* else if (flag == LOCAL_PROP) */
    head = p;	
    for(p = head->next_mod; p != head; p = p->next_mod)
    {
	if (p->module == module)
	{
	    a_mutex_unlock(&PropListLock);
	    Property_Error(err_ref, PERROR); /* a local exists	*/
	}
    }

    /* insert a new descriptor at the beginning	*/
    p = (property *) hg_alloc_size(sizeof(property));
    p->name = property_name;
    p->module = module;
    p->property_value.tag.kernel = TEND;
    p->next_mod = head->next_mod;
    head->next_mod = p;
    a_mutex_unlock(&PropListLock);
    
    a_mutex_lock(&ModuleLock);
    pm = (module_item *) (get_property(module, MODULE_PROP))->val.ptr;
    p->next_prop = pm->properties;
    pm->properties = p;
    a_mutex_unlock(&ModuleLock);

    return &p->property_value;
}
Example #25
0
static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
{
	unsigned int len;
	int i, width = 640, height = 480, depth = 8, pitch = 640;
	unsigned int flags, rsize, addr_prop = 0;
	unsigned long max_size = 0;
	u64 rstart, address = OF_BAD_ADDR;
	const u32 *pp, *addrp, *up;
	u64 asize;

	pp = get_property(dp, "linux,bootx-depth", &len);
	if (pp == NULL)
		pp = get_property(dp, "depth", &len);
	if (pp && len == sizeof(u32))
		depth = *pp;

	pp = get_property(dp, "linux,bootx-width", &len);
	if (pp == NULL)
		pp = get_property(dp, "width", &len);
	if (pp && len == sizeof(u32))
		width = *pp;

	pp = get_property(dp, "linux,bootx-height", &len);
	if (pp == NULL)
		pp = get_property(dp, "height", &len);
	if (pp && len == sizeof(u32))
		height = *pp;

	pp = get_property(dp, "linux,bootx-linebytes", &len);
	if (pp == NULL)
		pp = get_property(dp, "linebytes", &len);
	if (pp && len == sizeof(u32) && (*pp != 0xffffffffu))
		pitch = *pp;
	else
		pitch = width * ((depth + 7) / 8);

	rsize = (unsigned long)pitch * (unsigned long)height;

	/* Ok, now we try to figure out the address of the framebuffer.
	 *
	 * Unfortunately, Open Firmware doesn't provide a standard way to do
	 * so. All we can do is a dodgy heuristic that happens to work in
	 * practice. On most machines, the "address" property contains what
	 * we need, though not on Matrox cards found in IBM machines. What I've
	 * found that appears to give good results is to go through the PCI
	 * ranges and pick one that is both big enough and if possible encloses
	 * the "address" property. If none match, we pick the biggest
	 */
	up = get_property(dp, "linux,bootx-addr", &len);
	if (up == NULL)
		up = get_property(dp, "address", &len);
	if (up && len == sizeof(u32))
		addr_prop = *up;

	/* Hack for when BootX is passing us */
	if (no_real_node)
		goto skip_addr;

	for (i = 0; (addrp = of_get_address(dp, i, &asize, &flags))
		     != NULL; i++) {
		int match_addrp = 0;

		if (!(flags & IORESOURCE_MEM))
			continue;
		if (asize < rsize)
			continue;
		rstart = of_translate_address(dp, addrp);
		if (rstart == OF_BAD_ADDR)
			continue;
		if (addr_prop && (rstart <= addr_prop) &&
		    ((rstart + asize) >= (addr_prop + rsize)))
			match_addrp = 1;
		if (match_addrp) {
			address = addr_prop;
			break;
		}
		if (rsize > max_size) {
			max_size = rsize;
			address = OF_BAD_ADDR;
 		}

		if (address == OF_BAD_ADDR)
			address = rstart;
	}
 skip_addr:
	if (address == OF_BAD_ADDR && addr_prop)
		address = (u64)addr_prop;
	if (address != OF_BAD_ADDR) {
		/* kludge for valkyrie */
		if (strcmp(dp->name, "valkyrie") == 0)
			address += 0x1000;
		offb_init_fb(no_real_node ? "bootx" : dp->name,
			     no_real_node ? "display" : dp->full_name,
			     width, height, depth, pitch, address,
			     no_real_node ? NULL : dp);
	}
}
Example #26
0
int
erase_modular_property(dident functor, int property_name, dident module, type mod_tag, int which)
{
	register property	*p, **prev_p;
	int			res;
	module_item		*pm;

	if (which != GLOBAL_PROP && IsLocked(module)
	    && !IsModuleTag(module, mod_tag))
	{
	    return LOCKED;
	}

	/* this lookup must be before the lock */
	if (which != GLOBAL_PROP)
	    pm = (module_item *) (get_property(module, MODULE_PROP))->val.ptr;

	a_mutex_lock(&PropListLock);
	/* get pointer to property list from atom */
	prev_p = &(DidProperties(functor));
	p = *prev_p;

	/* scan property list until an entry for property is found or end */
	while (p)
	{
	    if (p->name == property_name)
	    {
		if (which != GLOBAL_PROP)
		{
		    register property	 *m, **prev_m;

		    prev_m = &(p->next_mod);
		    m = *prev_m;

		    while (m != p)	/* scan module list */
		    {
			if (m->module == module)
			{			/* erase the local	*/
			    *prev_m = m->next_mod;

			    _rem_from_module_entry(m, pm);
			    free_prop_value(property_name, &m->property_value);
			    hg_free_size((generic_ptr) m, sizeof(property));

			    if (p->next_mod == p && p->module == D_UNKNOWN)
			    {	/* all erased, remove head descriptor	*/
				*prev_p = p->next_prop;
				hg_free_size((generic_ptr) p, sizeof(property));
                              /* this is not an error, it is a message
                                 to notify that the property is erased
                                 completely */
                              res = PFAIL;
			      goto _unlock_return_;
			    }
			    res = PSUCCEED;
			    goto _unlock_return_;
			}
			prev_m = &(m->next_mod);
			m = *prev_m;
		    }
		}
		if (which != LOCAL_PROP  &&  p->module != D_UNKNOWN)
		{				/* erase the global	*/
		    free_prop_value(property_name, &p->property_value);
		    if (p->next_mod == p)
		    {		/* no locals: remove global descriptor	*/
			*prev_p = p->next_prop;
			hg_free_size((generic_ptr) p, sizeof(property));
                      /* this is not an error, it is a message to notify
                         that the property is erased completely       */
			res = PFAIL;
			goto _unlock_return_;
		    }
		    else
			p->module = D_UNKNOWN;	/* just mark it unused	*/
		    res = PSUCCEED;
		    goto _unlock_return_;
		}
		res = PERROR;
		goto _unlock_return_;		/* should give a warning */
	    }
	    prev_p = &(p->next_prop);
	    p = *prev_p;
	}
	res = PERROR;
_unlock_return_:
	a_mutex_unlock(&PropListLock);
        return(res);
}
/**
 * init_cache_info
 *
 * @returns pointer to cache_info on success, NULL otherwise
 */
static int
init_cache_info(struct dr_info *dr_info)
{
	struct cache_info *cache_list = NULL;
	DIR *d;
	struct dirent *ent;
	int rc;

	d = opendir(CPU_OFDT_BASE);
	if (d == NULL) {
		say(ERROR, "Could not open %s: %s\n", CPU_OFDT_BASE,
		    strerror(errno));
		return -1;
	}

	while ((ent = readdir(d))) {
		char path[DR_PATH_MAX];
		struct stat sb;

		/* skip everything but directories */
		sprintf(path, "/proc/device-tree/cpus/%s", ent->d_name);
		if (lstat(path, &sb)) {
			say(ERROR, "Could not access %s,\nstat(): %s\n",
			    path, strerror(errno));
			break;
		}

		if (!S_ISDIR(sb.st_mode))
			continue;

		if (strstr(ent->d_name, "-cache@")) {
			struct cache_info *cache;

			cache = zalloc(sizeof(*cache));
			if (cache == NULL) {
				say(ERROR, "Could not allocate cache info."
				    "\n%s\n", strerror(errno));
				free_cache_info(cache_list);
				return -1;
			}

			snprintf(cache->name, DR_BUF_SZ, "%s", ent->d_name);
			snprintf(cache->path, DR_BUF_SZ, "%s", path);

			cache->removed = 0;
			cache->next = cache_list;
			cache_list = cache;

			rc = get_property(cache->path, "ibm,phandle",
					  &cache->phandle,
					  sizeof(cache->phandle));
			if (rc) {
				say(ERROR, "Could not retreive ibm,phandle "
				    "property for %s\n", cache->path);
				free_cache_info(cache_list);
				return -1;
			}

			/* l3-caches do not have a l2-cache property */
			cache->l2cache = 0xffffffff;
			get_property(cache->path, "l2-cache", &cache->l2cache,
				     sizeof(cache->l2cache));

			say(DEBUG, "Found cache %s\n", cache->name);
		}
	}

	closedir(d);

	dr_info->all_caches = cache_list;
	return 0;
}
Example #28
0
int print_drconf_mem(struct cmd_opts *opts, struct lmb_list_head *lmb_list)
{
	struct dr_node *lmb;
	struct mem_scn *scn;
	int scn_offset = strlen("/sys/devices/system/memory/memory");
	char *aa_buf;
	__be32 *aa;
	int aa_size, aa_list_sz;
	int i, rc;
	uint32_t drc_index = 0;

	aa_size = get_property_size(DYNAMIC_RECONFIG_MEM,
				    "ibm,associativity-lookup-arrays");
	aa_buf = zalloc(aa_size);
	rc = get_property(DYNAMIC_RECONFIG_MEM,
			  "ibm,associativity-lookup-arrays", aa_buf, aa_size);
	if (rc) {
		say(ERROR, "Could not get associativity information.\n");
		return -1;
	}

	aa = (__be32 *)aa_buf;
	/* skip past the number of associativity lists */
	aa++;
	aa_list_sz = be32toh(*aa++);

	if (opts->s_name)
		drc_index = strtol(opts->s_name, NULL, 0);

	printf("Dynamic Reconfiguration Memory (LMB size 0x%x)\n",
	       lmb_list->lmbs->lmb_size);

	for (lmb = lmb_list->lmbs; lmb; lmb = lmb->next) {
		int first = 1;
		int aa_start, aa_end;

		if (drc_index && drc_index != lmb->drc_index)
			continue;
		else if ((output_level < DEBUG) && !lmb->is_owned)
			continue;

		printf("%s: %s\n", lmb->drc_name,
		       lmb->is_owned ? "" : "Not Owned");

		printf("    DRC Index: %x        Address: %lx\n",
		       lmb->drc_index, lmb->lmb_address);
		printf("    Removable: %s             Associativity: ",
		       lmb->is_removable ? "Yes" : "No ");

		if (lmb->lmb_aa_index == 0xffffffff) {
			printf("Not Set\n");
		} else {
			printf("(index: %d) ", lmb->lmb_aa_index);
			aa_start = lmb->lmb_aa_index * aa_list_sz;
			aa_end = aa_start + aa_list_sz;
			for (i = aa_start; i < aa_end; i++)
				printf("%d ", be32toh(aa[i]));
			printf("\n");
		}

		if (lmb->is_owned) {
			printf("    Section(s):");
			for (scn = lmb->lmb_mem_scns; scn; scn = scn->next) {
				if (first) {
					printf(" %s",
					       &scn->sysfs_path[scn_offset]);
					first = 0;
				} else
					printf(", %s",
					       &scn->sysfs_path[scn_offset]);
			}

			printf("\n");
		}
	}

	free(aa_buf);
	return 0;
}
Example #29
0
/* removes property --- if it's not there then ignore */
void
remove_property_nofetch(dbref player, const char *type)
{
    PropPtr l;
    char buf[BUFFER_LEN];
    char *w;

    /* if( tp_db_readonly ) return; *//* Why did we remove this? */

    w = strcpy(buf, type);

    l = DBFETCH(player)->properties;
    l = propdir_delete_elem(l, w);
    DBFETCH(player)->properties = l;
    if ((FLAGS(player) & LISTENER) && !(get_property(player, "_listen") ||
                                        get_property(player, "_olisten") ||
                                        get_property(player, "~listen") ||
                                        get_property(player, "~olisten") ||
                                        get_property(player, "@olisten") ||
                                        get_property(player, "@listen") ||
                                        get_property(player, "_alisten") ||
                                        get_property(player, "_aolisten") ||
                                        get_property(player, "~alisten") ||
                                        get_property(player, "~aolisten") ||
                                        get_property(player, "@aolisten") ||
                                        get_property(player, "@alisten")
        )) {
        FLAGS(player) &= ~LISTENER;
    }
    if ((FLAG2(player) & F2COMMAND) && !(get_property(player, "_command") ||
                                         get_property(player, "_ocommand") ||
                                         get_property(player, "~command") ||
                                         get_property(player, "~ocommand") ||
                                         get_property(player, "@ocommand") ||
                                         get_property(player, "@command")
        )) {
        FLAG2(player) &= ~F2COMMAND;
    }
    DBDIRTY(player);
}
Example #30
0
void
prim_array_filter_prop(PRIM_PROTOTYPE)
{
	char pattern[BUFFER_LEN];
	char tname[BUFFER_LEN];
	struct inst *in;
	struct inst temp1;
	stk_array *arr;
	stk_array *nu;
	char* prop;
	int len;

	CHECKOP(3);
	oper3 = POP();				/* str     pattern */
	oper2 = POP();				/* str     propname */
	oper1 = POP();				/* refarr  Array */
	if (oper1->type != PROG_ARRAY)
		abort_interp("Argument not an array. (1)");
	if (!array_is_homogenous(oper1->data.array, PROG_OBJECT))
		abort_interp("Argument not an array of dbrefs. (1)");
	if (oper2->type != PROG_STRING || !oper2->data.string)
		abort_interp("Argument not a non-null string. (2)");
	if (oper3->type != PROG_STRING)
		abort_interp("Argument not a string pattern. (3)");

	len = oper2->data.string ? oper2->data.string->length : 0;
	strcpyn(tname, sizeof(tname), DoNullInd(oper2->data.string));
	while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) {
		tname[len] = '\0';
	}

	nu = new_array_packed(0);
	arr = oper1->data.array;
	prop = tname;
	strcpyn(pattern, sizeof(pattern), DoNullInd(oper3->data.string));
	if (array_first(arr, &temp1)) {
		do {
			in = array_getitem(arr, &temp1);
			if (valid_object(in)) {
				ref = in->data.objref;
				CHECKREMOTE(ref);
				if (prop_read_perms(ProgUID, ref, prop, mlev)) {
					PropPtr pptr = get_property(ref, prop);

					if (pptr)
					{
						switch(PropType(pptr))
						{
							case PROP_STRTYP:
								strncpy(buf, PropDataStr(pptr), BUFFER_LEN);
							break;

							case PROP_LOKTYP:
								if (PropFlags(pptr) & PROP_ISUNLOADED) {
									strncpy(buf, "*UNLOCKED*", BUFFER_LEN);
								} else {
									strncpy(buf, unparse_boolexp(ProgUID, PropDataLok(pptr), 0), BUFFER_LEN);
								}
							break;

							case PROP_REFTYP:
								snprintf(buf, BUFFER_LEN, "#%i", PropDataRef(pptr));
							break;

							case PROP_INTTYP:
								snprintf(buf, BUFFER_LEN, "%i", PropDataVal(pptr));
							break;

							case PROP_FLTTYP:
								snprintf(buf, BUFFER_LEN, "%g", PropDataFVal(pptr));
							break;

							default:
								strncpy(buf, "", BUFFER_LEN);
							break;
						}
					}
					else
						strncpy(buf, "", BUFFER_LEN);

					if (equalstr(pattern, buf)) {
						array_appenditem(&nu, in);
					}
				}
			}
		} while (array_next(arr, &temp1));
	}

	CLEAR(oper3);
	CLEAR(oper2);
	CLEAR(oper1);

	PushArrayRaw(nu);
}