static unsigned int amd_xgbe_phy_resource_count(struct platform_device *pdev, unsigned int type) { unsigned int count; int i; for (i = 0, count = 0; i < pdev->num_resources; i++) { struct resource *r = &pdev->resource[i]; if (type == resource_type(r)) count++; } return count; }
static u32 _mali_osk_resource_irq(_mali_osk_resource_t *res) { int i; char name[32]; struct resource *resource; snprintf(name, sizeof(name), "%s_IRQ", res->description); for (i = 0; i < mali_platform_device->num_resources; i++) { resource = &mali_platform_device->resource[i]; if (IORESOURCE_IRQ == resource_type(resource) && !strncmp(name, resource->name, sizeof(name))) return resource->start; } return -1; }
static void vt1211_pnp_set_resources(struct device *dev) { struct resource *res; #if IS_ENABLED(CONFIG_CONSOLE_SERIAL) && IS_ENABLED(CONFIG_DRIVERS_UART_8250IO) /* TODO: Do the same for SP2? */ if (dev->path.pnp.device == VT1211_SP1) { for (res = dev->resource_list; res; res = res->next) { res->flags |= IORESOURCE_STORED; report_resource_stored(dev, res, ""); } return; } #endif pnp_enter_conf_mode(dev); pnp_set_logical_device(dev); /* Paranoia says I should disable the device here... */ for (res = dev->resource_list; res; res = res->next) { if (!(res->flags & IORESOURCE_ASSIGNED)) { printk(BIOS_ERR, "ERROR: %s %02lx %s size: 0x%010Lx " "not assigned\n", dev_path(dev), res->index, resource_type(res), res->size); continue; } /* Now store the resource. */ if (res->flags & IORESOURCE_IO) { vt1211_set_iobase(dev, res->index, res->base); } else if (res->flags & IORESOURCE_DRQ) { pnp_set_drq(dev, res->index, res->base); } else if (res->flags & IORESOURCE_IRQ) { pnp_set_irq(dev, res->index, res->base); } else { printk(BIOS_ERR, "ERROR: %s %02lx unknown resource " "type\n", dev_path(dev), res->index); return; } res->flags |= IORESOURCE_STORED; report_resource_stored(dev, res, ""); } pnp_exit_conf_mode(dev); }
void nvhost_device_unregister(struct nvhost_device *dev) { int i; if (dev) { device_del(&dev->dev); for (i = 0; i < dev->num_resources; i++) { struct resource *r = &dev->resource[i]; unsigned long type = resource_type(r); if (type == IORESOURCE_MEM || type == IORESOURCE_IO) release_resource(r); } put_device(&dev->dev); } }
/** * platform_get_resource_byname - get a resource for a device by name * @dev: platform device * @type: resource type * @name: resource name */ struct resource *platform_get_resource_byname(struct platform_device *dev, unsigned int type, const char *name) { int i; for (i = 0; i < dev->num_resources; i++) { struct resource *r = &dev->resource[i]; if (unlikely(!r->name)) continue; if (type == resource_type(r) && !strcmp(r->name, name)) return r; } return NULL; }
static int gen_pci_parse_request_of_pci_ranges(struct device *dev, struct list_head *resources, struct resource **bus_range) { int err, res_valid = 0; struct device_node *np = dev->of_node; resource_size_t iobase; struct resource_entry *win, *tmp; err = of_pci_get_host_bridge_resources(np, 0, 0xff, resources, &iobase); if (err) return err; err = devm_request_pci_bus_resources(dev, resources); if (err) return err; resource_list_for_each_entry_safe(win, tmp, resources) { struct resource *res = win->res; switch (resource_type(res)) { case IORESOURCE_IO: err = pci_remap_iospace(res, iobase); if (err) { dev_warn(dev, "error %d: failed to map resource %pR\n", err, res); resource_list_destroy_entry(win); } break; case IORESOURCE_MEM: res_valid |= !(res->flags & IORESOURCE_PREFETCH); break; case IORESOURCE_BUS: *bus_range = res; break; } } if (res_valid) return 0; dev_err(dev, "non-prefetchable memory resource required\n"); return -EINVAL; }
static void callback (Widget w, Resource * node, XmPushButtonCallbackStruct * pbcs) { int vi; have_xy = 0; lesstif_show_crosshair (0); if (pbcs->event && pbcs->event->type == KeyPress) { Dimension wx, wy; Widget aw = XtWindowToWidget (display, pbcs->event->xkey.window); action_x = pbcs->event->xkey.x; action_y = pbcs->event->xkey.y; if (aw) { Widget p = work_area; while (p && p != aw) { n = 0; stdarg (XmNx, &wx); stdarg (XmNy, &wy); XtGetValues (p, args, n); action_x -= wx; action_y -= wy; p = XtParent (p); } if (p == aw) have_xy = 1; } //printf("have xy from %s: %d %d\n", XtName(aw), action_x, action_y); } lesstif_need_idle_proc (); for (vi = 1; vi < node->c; vi++) if (resource_type (node->v[vi]) == 10) if (hid_parse_actions (node->v[vi].value)) return; }
static void add_resource_to_menu (Widget menu, Resource * node, XtCallbackProc callback) { int i, j; char *v; Widget sub, btn; Resource *r; for (i = 0; i < node->c; i++) switch (resource_type (node->v[i])) { case 101: /* named subnode */ n = 0; stdarg (XmNtearOffModel, XmTEAR_OFF_ENABLED); sub = XmCreatePulldownMenu (menu, node->v[i].name, args, n); XtSetValues (sub, args, n); n = 0; stdarg (XmNsubMenuId, sub); btn = XmCreateCascadeButton (menu, node->v[i].name, args, n); XtManageChild (btn); add_resource_to_menu (sub, node->v[i].subres, callback); break; case 1: /* unnamed subres */ n = 0; #if 0 if ((v = resource_value (node->v[i].subres, "fg"))) { do_color (v, XmNforeground); } if ((v = resource_value (node->v[i].subres, "bg"))) { do_color (v, XmNbackground); } if ((v = resource_value (node->v[i].subres, "font"))) { XFontStruct *fs = XLoadQueryFont (display, v); if (fs) { XmFontList fl = XmFontListCreate (fs, XmSTRING_DEFAULT_CHARSET); stdarg (XmNfontList, fl); } } #endif if ((v = resource_value (node->v[i].subres, "m"))) { stdarg (XmNmnemonic, v); } if ((r = resource_subres (node->v[i].subres, "a"))) { XmString as = XmStringCreateLocalized (r->v[0].value); stdarg (XmNacceleratorText, as); //stdarg(XmNaccelerator, r->v[1].value); note_accelerator (r->v[1].value, node->v[i].subres); } v = "button"; for (j = 0; j < node->v[i].subres->c; j++) if (resource_type (node->v[i].subres->v[j]) == 10) { v = node->v[i].subres->v[j].value; break; } stdarg (XmNlabelString, XmStringCreateLocalized (v)); if (node->v[i].subres->flags & FLAG_S) { int nn = n; stdarg (XmNtearOffModel, XmTEAR_OFF_ENABLED); sub = XmCreatePulldownMenu (menu, v, args + nn, n - nn); n = nn; stdarg (XmNsubMenuId, sub); btn = XmCreateCascadeButton (menu, "menubutton", args, n); XtManageChild (btn); add_resource_to_menu (sub, node->v[i].subres, callback); } else { Resource *radio = resource_subres (node->v[i].subres, "radio"); char *checked = resource_value (node->v[i].subres, "checked"); char *label = resource_value (node->v[i].subres, "sensitive"); if (radio) { ToggleItem *ti = (ToggleItem *) malloc (sizeof (ToggleItem)); ti->next = toggle_items; ti->group = radio->v[0].value; ti->item = radio->v[1].value; ti->callback = callback; ti->node = node->v[i].subres; toggle_items = ti; if (resource_value (node->v[i].subres, "set")) { stdarg (XmNset, True); } stdarg (XmNindicatorType, XmONE_OF_MANY); btn = XmCreateToggleButton (menu, "menubutton", args, n); ti->w = btn; XtAddCallback (btn, XmNvalueChangedCallback, (XtCallbackProc) radio_callback, (XtPointer) ti); } else if (checked) { if (strchr (checked, ',')) stdarg (XmNindicatorType, XmONE_OF_MANY); else stdarg (XmNindicatorType, XmN_OF_MANY); btn = XmCreateToggleButton (menu, "menubutton", args, n); XtAddCallback (btn, XmNvalueChangedCallback, callback, (XtPointer) node->v[i].subres); } else if (label && strcmp (label, "false") == 0) { stdarg (XmNalignment, XmALIGNMENT_BEGINNING); btn = XmCreateLabel (menu, "menulabel", args, n); } else { btn = XmCreatePushButton (menu, "menubutton", args, n); XtAddCallback (btn, XmNactivateCallback, callback, (XtPointer) node->v[i].subres); } for (j = 0; j < node->v[i].subres->c; j++) switch (resource_type (node->v[i].subres->v[j])) { case 110: /* named value = X resource */ { char *n = node->v[i].subres->v[j].name; if (strcmp (n, "fg") == 0) n = "foreground"; if (strcmp (n, "bg") == 0) n = "background"; if (strcmp (n, "m") == 0 || strcmp (n, "a") == 0 || strcmp (n, "sensitive") == 0) break; if (strcmp (n, "checked") == 0) { note_widget_flag (btn, XmNset, node->v[i].subres->v[j].value); break; } if (strcmp (n, "active") == 0) { note_widget_flag (btn, XmNsensitive, node->v[i].subres->v[j].value); break; } XtVaSetValues (btn, XtVaTypedArg, n, XtRString, node->v[i].subres->v[j].value, strlen (node->v[i].subres->v[j].value) + 1, NULL); } break; } XtManageChild (btn); } break; case 10: /* unnamed value */ n = 0; if (node->v[i].value[0] == '@') { if (strcmp (node->v[i].value, "@layerview") == 0) insert_layerview_buttons (menu); if (strcmp (node->v[i].value, "@layerpick") == 0) insert_layerpick_buttons (menu); if (strcmp (node->v[i].value, "@routestyles") == 0) lesstif_insert_style_buttons (menu); } else if (strcmp (node->v[i].value, "-") == 0) { btn = XmCreateSeparator (menu, "sep", args, n); XtManageChild (btn); } else if (i > 0) { btn = XmCreatePushButton (menu, node->v[i].value, args, n); XtManageChild (btn); } break; } }
static void __iomem *crb_map_res(struct device *dev, struct crb_priv *priv, struct resource *io_res, u64 start, u32 size) { struct resource new_res = { .start = start, .end = start + size - 1, .flags = IORESOURCE_MEM, }; /* Detect a 64 bit address on a 32 bit system */ if (start != new_res.start) return (void __iomem *) ERR_PTR(-EINVAL); if (!resource_contains(io_res, &new_res)) return devm_ioremap_resource(dev, &new_res); return priv->iobase + (new_res.start - io_res->start); } static int crb_map_io(struct acpi_device *device, struct crb_priv *priv, struct acpi_table_tpm2 *buf) { struct list_head resources; struct resource io_res; struct device *dev = &device->dev; u64 cmd_pa; u32 cmd_size; u64 rsp_pa; u32 rsp_size; int ret; INIT_LIST_HEAD(&resources); ret = acpi_dev_get_resources(device, &resources, crb_check_resource, &io_res); if (ret < 0) return ret; acpi_dev_free_resource_list(&resources); if (resource_type(&io_res) != IORESOURCE_MEM) { dev_err(dev, FW_BUG "TPM2 ACPI table does not define a memory resource\n"); return -EINVAL; } priv->iobase = devm_ioremap_resource(dev, &io_res); if (IS_ERR(priv->iobase)) return PTR_ERR(priv->iobase); priv->cca = crb_map_res(dev, priv, &io_res, buf->control_address, sizeof(struct crb_control_area)); if (IS_ERR(priv->cca)) return PTR_ERR(priv->cca); cmd_pa = ((u64) ioread32(&priv->cca->cmd_pa_high) << 32) | (u64) ioread32(&priv->cca->cmd_pa_low); cmd_size = ioread32(&priv->cca->cmd_size); priv->cmd = crb_map_res(dev, priv, &io_res, cmd_pa, cmd_size); if (IS_ERR(priv->cmd)) return PTR_ERR(priv->cmd); memcpy_fromio(&rsp_pa, &priv->cca->rsp_pa, 8); rsp_pa = le64_to_cpu(rsp_pa); rsp_size = ioread32(&priv->cca->rsp_size); if (cmd_pa != rsp_pa) { priv->rsp = crb_map_res(dev, priv, &io_res, rsp_pa, rsp_size); return PTR_ERR_OR_ZERO(priv->rsp); } /* According to the PTP specification, overlapping command and response * buffer sizes must be identical. */ if (cmd_size != rsp_size) { dev_err(dev, FW_BUG "overlapping command and response buffer sizes are not identical"); return -EINVAL; } priv->rsp = priv->cmd; return 0; } static int crb_acpi_add(struct acpi_device *device) { struct acpi_table_tpm2 *buf; struct crb_priv *priv; struct device *dev = &device->dev; acpi_status status; u32 sm; int rc; status = acpi_get_table(ACPI_SIG_TPM2, 1, (struct acpi_table_header **) &buf); if (ACPI_FAILURE(status) || buf->header.length < sizeof(*buf)) { dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n"); return -EINVAL; } /* Should the FIFO driver handle this? */ sm = buf->start_method; if (sm == ACPI_TPM2_MEMORY_MAPPED) return -ENODEV; priv = devm_kzalloc(dev, sizeof(struct crb_priv), GFP_KERNEL); if (!priv) return -ENOMEM; /* The reason for the extra quirk is that the PTT in 4th Gen Core CPUs * report only ACPI start but in practice seems to require both * ACPI start and CRB start. */ if (sm == ACPI_TPM2_COMMAND_BUFFER || sm == ACPI_TPM2_MEMORY_MAPPED || !strcmp(acpi_device_hid(device), "MSFT0101")) priv->flags |= CRB_FL_CRB_START; if (sm == ACPI_TPM2_START_METHOD || sm == ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD) priv->flags |= CRB_FL_ACPI_START; rc = crb_map_io(device, priv, buf); if (rc) return rc; return crb_init(device, priv); } static int crb_acpi_remove(struct acpi_device *device) { struct device *dev = &device->dev; struct tpm_chip *chip = dev_get_drvdata(dev); tpm_chip_unregister(chip); return 0; } static struct acpi_device_id crb_device_ids[] = { {"MSFT0101", 0}, {"", 0}, }; MODULE_DEVICE_TABLE(acpi, crb_device_ids); static struct acpi_driver crb_acpi_driver = { .name = "tpm_crb", .ids = crb_device_ids, .ops = { .add = crb_acpi_add, .remove = crb_acpi_remove, }, .drv = { .pm = &crb_pm, }, };
/*! \brief Translate a resource tree into a menu structure * * \param [in] menu The GHidMainMenu widget to be acted on * \param [in] shall The base menu shell (a menu bar or popup menu) * \param [in] res The base of the resource tree * */ void ghid_main_menu_real_add_resource (GHidMainMenu *menu, GtkMenuShell *shell, const Resource *res) { int i, j; const Resource *tmp_res; gchar mnemonic = 0; for (i = 0; i < res->c; ++i) { const gchar *accel = NULL; char *menu_label; const char *res_val; const Resource *sub_res = res->v[i].subres; GtkAction *action = NULL; switch (resource_type (res->v[i])) { case 101: /* name, subres: passthrough */ ghid_main_menu_real_add_resource (menu, shell, sub_res); break; case 1: /* no name, subres */ tmp_res = resource_subres (sub_res, "a"); /* accelerator */ res_val = resource_value (sub_res, "m"); /* mnemonic */ if (res_val) mnemonic = res_val[0]; /* The accelerator resource will have two values, like * a={"Ctrl-Q" "Ctrl<Key>q"} * The first Gtk ignores. The second needs to be translated. */ if (tmp_res) accel = check_unique_accel (translate_accelerator (tmp_res->v[1].value)); /* Now look for the first unnamed value (not a subresource) to * figure out the name of the menu or the menuitem. */ res_val = "button"; for (j = 0; j < sub_res->c; ++j) if (resource_type (sub_res->v[j]) == 10) { res_val = _(sub_res->v[j].value); break; } /* Hack '_' in based on mnemonic value */ if (!mnemonic) menu_label = g_strdup (res_val); else { char *post_ = strchr (res_val, mnemonic); if (post_ == NULL) menu_label = g_strdup (res_val); else { GString *tmp = g_string_new (""); g_string_append_len (tmp, res_val, post_ - res_val); g_string_append_c (tmp, '_'); g_string_append (tmp, post_); menu_label = g_string_free (tmp, FALSE); } } /* If the subresource we're processing also has unnamed * subresources, it's a submenu, not a regular menuitem. */ if (sub_res->flags & FLAG_S) { /* SUBMENU */ GtkWidget *submenu = gtk_menu_new (); GtkWidget *item = gtk_menu_item_new_with_mnemonic (menu_label); GtkWidget *tearoff = gtk_tearoff_menu_item_new (); gtk_menu_shell_append (shell, item); gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu); /* add tearoff to menu */ gtk_menu_shell_append (GTK_MENU_SHELL (submenu), tearoff); /* recurse on the newly-added submenu */ ghid_main_menu_real_add_resource (menu, GTK_MENU_SHELL (submenu), sub_res); } else { /* NON-SUBMENU: MENU ITEM */ const char *checked = resource_value (sub_res, "checked"); const char *label = resource_value (sub_res, "sensitive"); const char *tip = resource_value (sub_res, "tip"); if (checked) { /* TOGGLE ITEM */ gchar *name = g_strdup_printf ("MainMenuAction%d", action_counter++); action = GTK_ACTION (gtk_toggle_action_new (name, menu_label, tip, NULL)); /* checked=foo is a binary flag (checkbox) * checked=foo,bar is a flag compared to a value (radio) */ gtk_toggle_action_set_draw_as_radio (GTK_TOGGLE_ACTION (action), !!strchr (checked, ',')); } else if (label && strcmp (label, "false") == 0) { /* INSENSITIVE ITEM */ GtkWidget *item = gtk_menu_item_new_with_label (menu_label); gtk_widget_set_sensitive (item, FALSE); gtk_menu_shell_append (shell, item); } else { /* NORMAL ITEM */ gchar *name = g_strdup_printf ("MainMenuAction%d", action_counter++); action = gtk_action_new (name, menu_label, tip, NULL); } } /* Connect accelerator, if there is one */ if (action) { GtkWidget *item; gtk_action_set_accel_group (action, menu->accel_group); gtk_action_group_add_action_with_accel (menu->action_group, action, accel); gtk_action_connect_accelerator (action); g_signal_connect (G_OBJECT (action), "activate", menu->action_cb, (gpointer) sub_res); g_object_set_data (G_OBJECT (action), "resource", (gpointer) sub_res); item = gtk_action_create_menu_item (action); gtk_menu_shell_append (shell, item); menu->actions = g_list_append (menu->actions, action); menu->special_key_cb (accel, action, sub_res); } /* Scan rest of resource in case there is more work */ for (j = 0; j < sub_res->c; j++) { const char *res_name; /* named value = X resource */ if (resource_type (sub_res->v[j]) == 110) { res_name = sub_res->v[j].name; /* translate bg, fg to background, foreground */ if (strcmp (res_name, "fg") == 0) res_name = "foreground"; if (strcmp (res_name, "bg") == 0) res_name = "background"; /* ignore special named values (m, a, sensitive) */ if (strcmp (res_name, "m") == 0 || strcmp (res_name, "a") == 0 || strcmp (res_name, "sensitive") == 0 || strcmp (res_name, "tip") == 0) break; /* log checked and active special values */ if (action && strcmp (res_name, "checked") == 0) g_object_set_data (G_OBJECT (action), "checked-flag", sub_res->v[j].value); else if (action && strcmp (res_name, "active") == 0) g_object_set_data (G_OBJECT (action), "active-flag", sub_res->v[j].value); else /* if we got this far it is supposed to be an X * resource. For now ignore it and warn the user */ Message (_("The gtk gui currently ignores \"%s\"" "as part of a menuitem resource.\n" "Feel free to provide patches\n"), sub_res->v[j].value); } } break; case 10: /* no name, value */ /* If we get here, the resource is "-" or "@foo" for some foo */ if (res->v[i].value[0] == '@') { GList *children; int pos; children = gtk_container_get_children (GTK_CONTAINER (shell)); pos = g_list_length (children); g_list_free (children); if (strcmp (res->v[i].value, "@layerview") == 0) { menu->layer_view_shell = shell; menu->layer_view_pos = pos; } else if (strcmp (res->v[i].value, "@layerpick") == 0) { menu->layer_pick_shell = shell; menu->layer_pick_pos = pos; } else if (strcmp (res->v[i].value, "@routestyles") == 0) { menu->route_style_shell = shell; menu->route_style_pos = pos; } else Message (_("GTK GUI currently ignores \"%s\" in the menu\n" "resource file.\n"), res->v[i].value); } else if (strcmp (res->v[i].value, "-") == 0) { GtkWidget *item = gtk_separator_menu_item_new (); gtk_menu_shell_append (shell, item); } else if (i > 0) { /* This is an action-less menuitem. It is really only useful * when you're starting to build a new menu and you're looking * to get the layout right. */ GtkWidget *item = gtk_menu_item_new_with_label (_(res->v[i].value)); gtk_menu_shell_append (shell, item); } break; } } }
static int xen_map_device_mmio(const struct resource *resources, unsigned int count) { unsigned int i, j, nr; int rc = 0; const struct resource *r; xen_pfn_t *gpfns; xen_ulong_t *idxs; int *errs; for (i = 0; i < count; i++) { struct xen_add_to_physmap_range xatp = { .domid = DOMID_SELF, .space = XENMAPSPACE_dev_mmio }; r = &resources[i]; nr = DIV_ROUND_UP(resource_size(r), XEN_PAGE_SIZE); if ((resource_type(r) != IORESOURCE_MEM) || (nr == 0)) continue; gpfns = kzalloc(sizeof(xen_pfn_t) * nr, GFP_KERNEL); idxs = kzalloc(sizeof(xen_ulong_t) * nr, GFP_KERNEL); errs = kzalloc(sizeof(int) * nr, GFP_KERNEL); if (!gpfns || !idxs || !errs) { kfree(gpfns); kfree(idxs); kfree(errs); rc = -ENOMEM; goto unmap; } for (j = 0; j < nr; j++) { /* * The regions are always mapped 1:1 to DOM0 and this is * fine because the memory map for DOM0 is the same as * the host (except for the RAM). */ gpfns[j] = XEN_PFN_DOWN(r->start) + j; idxs[j] = XEN_PFN_DOWN(r->start) + j; } xatp.size = nr; set_xen_guest_handle(xatp.gpfns, gpfns); set_xen_guest_handle(xatp.idxs, idxs); set_xen_guest_handle(xatp.errs, errs); rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap_range, &xatp); kfree(gpfns); kfree(idxs); kfree(errs); if (rc) goto unmap; } return rc; unmap: xen_unmap_device_mmio(resources, i); return rc; }
/** * platform_device_add - add a platform device to device hierarchy * @pdev: platform device we're adding * * This is part 2 of platform_device_register(), though may be called * separately _iff_ pdev was allocated by platform_device_alloc(). */ int platform_device_add(struct platform_device *pdev) { int i, ret; if (!pdev) return -EINVAL; if (!pdev->dev.parent) pdev->dev.parent = &platform_bus; pdev->dev.bus = &platform_bus_type; switch (pdev->id) { default: dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id); break; case PLATFORM_DEVID_NONE: dev_set_name(&pdev->dev, "%s", pdev->name); break; case PLATFORM_DEVID_AUTO: /* * Automatically allocated device ID. We mark it as such so * that we remember it must be freed, and we append a suffix * to avoid namespace collision with explicit IDs. */ ret = ida_simple_get(&platform_devid_ida, 0, 0, GFP_KERNEL); if (ret < 0) goto err_out; pdev->id = ret; pdev->id_auto = true; dev_set_name(&pdev->dev, "%s.%d.auto", pdev->name, pdev->id); break; } for (i = 0; i < pdev->num_resources; i++) { struct resource *p, *r = &pdev->resource[i]; if (r->name == NULL) r->name = dev_name(&pdev->dev); p = r->parent; if (!p) { if (resource_type(r) == IORESOURCE_MEM) p = &iomem_resource; else if (resource_type(r) == IORESOURCE_IO) p = &ioport_resource; } if (p) { ret = insert_resource(p, r); if (ret) { dev_err(&pdev->dev, "failed to claim resource %d: %pR\n", i, r); goto failed; } } } pr_debug("Registering platform device '%s'. Parent at %s\n", dev_name(&pdev->dev), dev_name(pdev->dev.parent)); ret = device_add(&pdev->dev); if (ret == 0) return ret; failed: if (pdev->id_auto) { ida_simple_remove(&platform_devid_ida, pdev->id); pdev->id = PLATFORM_DEVID_AUTO; } while (--i >= 0) { struct resource *r = &pdev->resource[i]; if (r->parent) release_resource(r); } err_out: return ret; }
int ActionLoadVendorFrom (int argc, char **argv, Coord x, Coord y) { int i; char *fname = NULL; static char *default_file = NULL; char *sval; Resource *res, *drcres, *drlres; int type; bool free_fname = false; cached_drill = -1; fname = argc ? argv[0] : 0; if (!fname || !*fname) { fname = gui->fileselect (_("Load Vendor Resource File..."), _("Picks a vendor resource file to load.\n" "This file can contain drc settings for a\n" "particular vendor as well as a list of\n" "predefined drills which are allowed."), default_file, ".res", "vendor", HID_FILESELECT_READ); if (fname == NULL) AFAIL (load_vendor); free_fname = true; free (default_file); default_file = NULL; if (fname && *fname) default_file = strdup (fname); } /* Unload any vendor table we may have had */ n_vendor_drills = 0; n_refdes = 0; n_value = 0; n_descr = 0; FREE (vendor_drills); FREE (ignore_refdes); FREE (ignore_value); FREE (ignore_descr); /* load the resource file */ res = resource_parse (fname, NULL); if (res == NULL) { Message (_("Could not load vendor resource file \"%s\"\n"), fname); return 1; } /* figure out the vendor name, if specified */ vendor_name = (char *)UNKNOWN (resource_value (res, "vendor")); /* figure out the units, if specified */ sval = resource_value (res, "units"); if (sval == NULL) { sf = MIL_TO_COORD(1); } else if ((NSTRCMP (sval, "mil") == 0) || (NSTRCMP (sval, "mils") == 0)) { sf = MIL_TO_COORD(1); } else if ((NSTRCMP (sval, "inch") == 0) || (NSTRCMP (sval, "inches") == 0)) { sf = INCH_TO_COORD(1); } else if (NSTRCMP (sval, "mm") == 0) { sf = MM_TO_COORD(1); } else { Message ("\"%s\" is not a supported units. Defaulting to inch\n", sval); sf = INCH_TO_COORD(1); } /* default to ROUND_UP */ rounding_method = ROUND_UP; /* extract the drillmap resource */ drlres = resource_subres (res, "drillmap"); if (drlres == NULL) { Message (_("No drillmap resource found\n")); } else { sval = resource_value (drlres, "round"); if (sval != NULL) { if (NSTRCMP (sval, "up") == 0) { rounding_method = ROUND_UP; } else if (NSTRCMP (sval, "nearest") == 0) { rounding_method = CLOSEST; } else { Message (_ ("\"%s\" is not a valid rounding type. Defaulting to up\n"), sval); rounding_method = ROUND_UP; } } process_skips (resource_subres (drlres, "skips")); for (i = 0; i < drlres->c; i++) { type = resource_type (drlres->v[i]); switch (type) { case 10: /* just a number */ add_to_drills (drlres->v[i].value); break; default: break; } } } /* Extract the DRC resource */ drcres = resource_subres (res, "drc"); sval = resource_value (drcres, "copper_space"); if (sval != NULL) { PCB->Bloat = floor (sf * atof (sval) + 0.5); Message (_("Set DRC minimum copper spacing to %.2f mils\n"), 0.01 * PCB->Bloat); } sval = resource_value (drcres, "copper_overlap"); if (sval != NULL) { PCB->Shrink = floor (sf * atof (sval) + 0.5); Message (_("Set DRC minimum copper overlap to %.2f mils\n"), 0.01 * PCB->Shrink); } sval = resource_value (drcres, "copper_width"); if (sval != NULL) { PCB->minWid = floor (sf * atof (sval) + 0.5); Message (_("Set DRC minimum copper spacing to %.2f mils\n"), 0.01 * PCB->minWid); } sval = resource_value (drcres, "silk_width"); if (sval != NULL) { PCB->minSlk = floor (sf * atof (sval) + 0.5); Message (_("Set DRC minimum silk width to %.2f mils\n"), 0.01 * PCB->minSlk); } sval = resource_value (drcres, "min_drill"); if (sval != NULL) { PCB->minDrill = floor (sf * atof (sval) + 0.5); Message (_("Set DRC minimum drill diameter to %.2f mils\n"), 0.01 * PCB->minDrill); } sval = resource_value (drcres, "min_ring"); if (sval != NULL) { PCB->minRing = floor (sf * atof (sval) + 0.5); Message (_("Set DRC minimum annular ring to %.2f mils\n"), 0.01 * PCB->minRing); } Message (_("Loaded %d vendor drills from %s\n"), n_vendor_drills, fname); Message (_("Loaded %d RefDes skips, %d Value skips, %d Descr skips\n"), n_refdes, n_value, n_descr); vendorMapEnable = true; apply_vendor_map (); if (free_fname) free (fname); return 0; }
/** * omap_device_fixup_resources - Fix platform device resources * @od: struct omap_device * * * Fixup the platform device resources so that the resources * from the hwmods are included for. */ static int omap_device_fixup_resources(struct omap_device *od) { struct platform_device *pdev = od->pdev; int i, j, ret, res_count; struct resource *res, *r, *rnew, *rn; unsigned long type; /* * DT Boot: * OF framework will construct the resource structure (currently * does for MEM & IRQ resource) and we should respect/use these * resources, killing hwmod dependency. * If pdev->num_resources > 0, we assume that MEM & IRQ resources * have been allocated by OF layer already (through DTB). * * Non-DT Boot: * Here, pdev->num_resources = 0, and we should get all the * resources from hwmod. * * TODO: Once DMA resource is available from OF layer, we should * kill filling any resources from hwmod. */ /* count number of resources hwmod provides */ res_count = omap_device_count_resources(od, IORESOURCE_IRQ | IORESOURCE_DMA | IORESOURCE_MEM); /* if no resources from hwmod, we're done already */ if (res_count == 0) return 0; /* Allocate resources memory to account for all hwmod resources */ res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL); if (!res) { ret = -ENOMEM; goto fail_no_res; } /* fill all the resources */ ret = omap_device_fill_resources(od, res); if (ret != 0) goto fail_no_fill; /* * If pdev->num_resources > 0, then assume that, * MEM and IRQ resources will only come from DT and only * fill DMA resource from hwmod layer. */ if (pdev->num_resources > 0) { dev_dbg(&pdev->dev, "%s(): resources allocated %d hwmod #%d\n", __func__, pdev->num_resources, res_count); /* find number of resources needing to be inserted */ for (i = 0, j = 0, r = res; i < res_count; i++, r++) { type = resource_type(r); if (type == IORESOURCE_DMA) j++; } /* no need to insert anything, just return */ if (j == 0) { kfree(res); return 0; } /* we need to insert j additional resources */ rnew = kzalloc(sizeof(*rnew) * (pdev->num_resources + j), GFP_KERNEL); if (rnew == NULL) goto fail_no_rnew; /* * Unlink any resources from any lists. * This is important since the copying destroys any * linkage */ for (i = 0, r = pdev->resource; i < pdev->num_resources; i++, r++) { if (!r->parent) continue; dev_dbg(&pdev->dev, "Releasing resource %p\n", r); release_resource(r); r->parent = NULL; r->sibling = NULL; r->child = NULL; } memcpy(rnew, pdev->resource, sizeof(*rnew) * pdev->num_resources); /* now append the resources from the hwmods */ rn = rnew + pdev->num_resources; for (i = 0, r = res; i < res_count; i++, r++) { type = resource_type(r); if (type != IORESOURCE_DMA) continue; /* append the hwmod resource */ memcpy(rn, r, sizeof(*r)); /* make sure these are zeroed out */ rn->parent = NULL; rn->child = NULL; rn->sibling = NULL; rn++; } kfree(res); /* we don't need res anymore */ /* this is our new resource table */ res = rnew; res_count = j + pdev->num_resources; } else { dev_dbg(&pdev->dev, "%s(): using resources from hwmod %d\n", __func__, res_count); } ret = platform_device_add_resources(pdev, res, res_count); kfree(res); /* failed to add the resources? */ if (ret != 0) return ret; /* finally link all the resources again */ ret = platform_device_link_resources(pdev); if (ret != 0) return ret; return 0; fail_no_rnew: /* nothing */ fail_no_fill: kfree(res); fail_no_res: return ret; }
static int sh_pfc_map_resources(struct sh_pfc *pfc, struct platform_device *pdev) { unsigned int num_windows = 0; unsigned int num_irqs = 0; struct sh_pfc_window *windows; unsigned int *irqs = NULL; struct resource *res; unsigned int i; /* Count the MEM and IRQ resources. */ for (i = 0; i < pdev->num_resources; ++i) { switch (resource_type(&pdev->resource[i])) { case IORESOURCE_MEM: num_windows++; break; case IORESOURCE_IRQ: num_irqs++; break; } } if (num_windows == 0) return -EINVAL; /* Allocate memory windows and IRQs arrays. */ windows = devm_kzalloc(pfc->dev, num_windows * sizeof(*windows), GFP_KERNEL); if (windows == NULL) return -ENOMEM; pfc->num_windows = num_windows; pfc->windows = windows; if (num_irqs) { irqs = devm_kzalloc(pfc->dev, num_irqs * sizeof(*irqs), GFP_KERNEL); if (irqs == NULL) return -ENOMEM; pfc->num_irqs = num_irqs; pfc->irqs = irqs; } /* Fill them. */ for (i = 0, res = pdev->resource; i < pdev->num_resources; i++, res++) { switch (resource_type(res)) { case IORESOURCE_MEM: windows->phys = res->start; windows->size = resource_size(res); windows->virt = devm_ioremap_resource(pfc->dev, res); if (IS_ERR(windows->virt)) return -ENOMEM; windows++; break; case IORESOURCE_IRQ: *irqs++ = res->start; break; } } return 0; }
void load_mouse_resource (const Resource *res) { int bi, mi, a; int action_count; #ifdef DEBUG_HID_RESOURCE fprintf(stderr, "note mouse resource:\n"); resource_dump (res); #endif button_count = res->c; button_nums = (int *)malloc(res->c * sizeof(int)); mod_count = (int *)malloc(res->c * sizeof(int)); action_count = 0; for (bi=0; bi<res->c; bi++) { if (res->v[bi].value) action_count++; if (res->v[bi].subres) action_count += res->v[bi].subres->c; } mods = (unsigned int *)malloc(action_count * sizeof(int)); actions = (Resource **)malloc(action_count * sizeof(Resource*)); a = 0; for (bi=0; bi<res->c; bi++) { int button_num = button_name_to_num(res->v[bi].name); if (button_num < 0) continue; button_nums[bi] = button_num; mod_count[bi] = 0; if (res->v[bi].value) { mods[a] = 0; actions[a++] = res_wrap (res->v[bi].value); mod_count[bi] = 1; } if (res->v[bi].subres) { Resource *m = res->v[bi].subres; mod_count[bi] += m->c; for (mi=0; mi<m->c; mi++, a++) { switch (resource_type (m->v[mi])) { case 1: /* subres only */ mods[a] = 0; actions[a] = m->v[mi].subres; break; case 10: /* value only */ mods[a] = 0; actions[a] = res_wrap (m->v[mi].value); break; case 101: /* name = subres */ mods[a] = parse_mods (m->v[mi].name); actions[a] = m->v[mi].subres; break; case 110: /* name = value */ mods[a] = parse_mods (m->v[mi].name); actions[a] = res_wrap (m->v[mi].value); break; } } } } }
static void __iomem *crb_map_res(struct device *dev, struct crb_priv *priv, struct resource *io_res, u64 start, u32 size) { struct resource new_res = { .start = start, .end = start + size - 1, .flags = IORESOURCE_MEM, }; /* Detect a 64 bit address on a 32 bit system */ if (start != new_res.start) return (void __iomem *) ERR_PTR(-EINVAL); if (!resource_contains(io_res, &new_res)) return devm_ioremap_resource(dev, &new_res); return priv->iobase + (new_res.start - io_res->start); } /* * Work around broken BIOSs that return inconsistent values from the ACPI * region vs the registers. Trust the ACPI region. Such broken systems * probably cannot send large TPM commands since the buffer will be truncated. */ static u64 crb_fixup_cmd_size(struct device *dev, struct resource *io_res, u64 start, u64 size) { if (io_res->start > start || io_res->end < start) return size; if (start + size - 1 <= io_res->end) return size; dev_err(dev, FW_BUG "ACPI region does not cover the entire command/response buffer. %pr vs %llx %llx\n", io_res, start, size); return io_res->end - start + 1; } static int crb_map_io(struct acpi_device *device, struct crb_priv *priv, struct acpi_table_tpm2 *buf) { struct list_head resources; struct resource io_res; struct device *dev = &device->dev; u32 pa_high, pa_low; u64 cmd_pa; u32 cmd_size; __le64 __rsp_pa; u64 rsp_pa; u32 rsp_size; int ret; INIT_LIST_HEAD(&resources); ret = acpi_dev_get_resources(device, &resources, crb_check_resource, &io_res); if (ret < 0) return ret; acpi_dev_free_resource_list(&resources); if (resource_type(&io_res) != IORESOURCE_MEM) { dev_err(dev, FW_BUG "TPM2 ACPI table does not define a memory resource\n"); return -EINVAL; } priv->iobase = devm_ioremap_resource(dev, &io_res); if (IS_ERR(priv->iobase)) return PTR_ERR(priv->iobase); /* The ACPI IO region starts at the head area and continues to include * the control area, as one nice sane region except for some older * stuff that puts the control area outside the ACPI IO region. */ if ((priv->sm == ACPI_TPM2_COMMAND_BUFFER) || (priv->sm == ACPI_TPM2_MEMORY_MAPPED)) { if (buf->control_address == io_res.start + sizeof(*priv->regs_h)) priv->regs_h = priv->iobase; else dev_warn(dev, FW_BUG "Bad ACPI memory layout"); } ret = __crb_request_locality(dev, priv, 0); if (ret) return ret; priv->regs_t = crb_map_res(dev, priv, &io_res, buf->control_address, sizeof(struct crb_regs_tail)); if (IS_ERR(priv->regs_t)) return PTR_ERR(priv->regs_t); /* * PTT HW bug w/a: wake up the device to access * possibly not retained registers. */ ret = crb_cmd_ready(dev, priv); if (ret) return ret; pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high); pa_low = ioread32(&priv->regs_t->ctrl_cmd_pa_low); cmd_pa = ((u64)pa_high << 32) | pa_low; cmd_size = crb_fixup_cmd_size(dev, &io_res, cmd_pa, ioread32(&priv->regs_t->ctrl_cmd_size)); dev_dbg(dev, "cmd_hi = %X cmd_low = %X cmd_size %X\n", pa_high, pa_low, cmd_size); priv->cmd = crb_map_res(dev, priv, &io_res, cmd_pa, cmd_size); if (IS_ERR(priv->cmd)) { ret = PTR_ERR(priv->cmd); goto out; } memcpy_fromio(&__rsp_pa, &priv->regs_t->ctrl_rsp_pa, 8); rsp_pa = le64_to_cpu(__rsp_pa); rsp_size = crb_fixup_cmd_size(dev, &io_res, rsp_pa, ioread32(&priv->regs_t->ctrl_rsp_size)); if (cmd_pa != rsp_pa) { priv->rsp = crb_map_res(dev, priv, &io_res, rsp_pa, rsp_size); ret = PTR_ERR_OR_ZERO(priv->rsp); goto out; } /* According to the PTP specification, overlapping command and response * buffer sizes must be identical. */ if (cmd_size != rsp_size) { dev_err(dev, FW_BUG "overlapping command and response buffer sizes are not identical"); ret = -EINVAL; goto out; } priv->rsp = priv->cmd; out: if (!ret) priv->cmd_size = cmd_size; crb_go_idle(dev, priv); __crb_relinquish_locality(dev, priv, 0); return ret; } static int crb_acpi_add(struct acpi_device *device) { struct acpi_table_tpm2 *buf; struct crb_priv *priv; struct tpm_chip *chip; struct device *dev = &device->dev; struct tpm2_crb_smc *crb_smc; acpi_status status; u32 sm; int rc; status = acpi_get_table(ACPI_SIG_TPM2, 1, (struct acpi_table_header **) &buf); if (ACPI_FAILURE(status) || buf->header.length < sizeof(*buf)) { dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n"); return -EINVAL; } /* Should the FIFO driver handle this? */ sm = buf->start_method; if (sm == ACPI_TPM2_MEMORY_MAPPED) return -ENODEV; priv = devm_kzalloc(dev, sizeof(struct crb_priv), GFP_KERNEL); if (!priv) return -ENOMEM; if (sm == ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC) { if (buf->header.length < (sizeof(*buf) + sizeof(*crb_smc))) { dev_err(dev, FW_BUG "TPM2 ACPI table has wrong size %u for start method type %d\n", buf->header.length, ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC); return -EINVAL; } crb_smc = ACPI_ADD_PTR(struct tpm2_crb_smc, buf, sizeof(*buf)); priv->smc_func_id = crb_smc->smc_func_id; } priv->sm = sm; priv->hid = acpi_device_hid(device); rc = crb_map_io(device, priv, buf); if (rc) return rc; chip = tpmm_chip_alloc(dev, &tpm_crb); if (IS_ERR(chip)) return PTR_ERR(chip); dev_set_drvdata(&chip->dev, priv); chip->acpi_dev_handle = device->handle; chip->flags = TPM_CHIP_FLAG_TPM2; rc = __crb_request_locality(dev, priv, 0); if (rc) return rc; rc = crb_cmd_ready(dev, priv); if (rc) goto out; pm_runtime_get_noresume(dev); pm_runtime_set_active(dev); pm_runtime_enable(dev); rc = tpm_chip_register(chip); if (rc) { crb_go_idle(dev, priv); pm_runtime_put_noidle(dev); pm_runtime_disable(dev); goto out; } pm_runtime_put_sync(dev); out: __crb_relinquish_locality(dev, priv, 0); return rc; } static int crb_acpi_remove(struct acpi_device *device) { struct device *dev = &device->dev; struct tpm_chip *chip = dev_get_drvdata(dev); tpm_chip_unregister(chip); pm_runtime_disable(dev); return 0; } static int __maybe_unused crb_pm_runtime_suspend(struct device *dev) { struct tpm_chip *chip = dev_get_drvdata(dev); struct crb_priv *priv = dev_get_drvdata(&chip->dev); return crb_go_idle(dev, priv); } static int __maybe_unused crb_pm_runtime_resume(struct device *dev) { struct tpm_chip *chip = dev_get_drvdata(dev); struct crb_priv *priv = dev_get_drvdata(&chip->dev); return crb_cmd_ready(dev, priv); } static int __maybe_unused crb_pm_suspend(struct device *dev) { int ret; ret = tpm_pm_suspend(dev); if (ret) return ret; return crb_pm_runtime_suspend(dev); }
int lesstif_key_event (XKeyEvent * e) { char buf[10], buf2[10]; KeySym sym, sym2; int slen, slen2; int mods = 0; int i, vi; static int sorted = 0; acc_table_t *my_table = 0; if (!sorted) { sorted = 1; qsort (acc_table, acc_num, sizeof (acc_table_t), acc_sort_rev); } if (e->state & ShiftMask) mods |= M_Shift; if (e->state & ControlMask) mods |= M_Ctrl; if (e->state & Mod1Mask) mods |= M_Alt; e->state &= ~(ControlMask | Mod1Mask); slen = XLookupString (e, buf, sizeof (buf), &sym, NULL); if (e->state & ShiftMask) { e->state &= ~ShiftMask; slen2 = XLookupString (e, buf2, sizeof (buf2), &sym2, NULL); } else slen2 = slen; /* Ignore these. */ switch (sym) { case XK_Shift_L: case XK_Shift_R: case XK_Control_L: case XK_Control_R: case XK_Caps_Lock: case XK_Shift_Lock: case XK_Meta_L: case XK_Meta_R: case XK_Alt_L: case XK_Alt_R: case XK_Super_L: case XK_Super_R: case XK_Hyper_L: case XK_Hyper_R: return 1; } if (cur_table == 0) { cur_table = acc_table; cur_ntable = acc_num; } //printf("\nmods %x key %d str `%s' in %p/%d\n", mods, (int)sym, buf, cur_table, cur_ntable); #define KM(m) ((m) & ~M_Multi) for (i = 0; i < cur_ntable; i++) { dump_multi (i, 0, cur_table+i, 1); if (KM(cur_table[i].mods) == mods) { if (sym == acc_table[i].u.a.key) break; } if (KM(cur_table[i].mods) == (mods & ~M_Shift)) { if (slen == 1 && buf[0] == cur_table[i].key_char) break; if (sym == cur_table[i].u.a.key) break; } if (mods & M_Shift && KM(cur_table[i].mods) == mods) { if (slen2 == 1 && buf2[0] == cur_table[i].key_char) break; if (sym2 == acc_table[i].u.a.key) break; } } if (i == cur_ntable) { if (cur_table == acc_table) lesstif_log ("Key \"%s\" not tied to an action\n", buf); else lesstif_log ("Key \"%s\" not tied to a multi-key action\n", buf); cur_table = 0; return 0; } if (cur_table[i].mods & M_Multi) { cur_ntable = cur_table[i].u.c.n_chain; cur_table = cur_table[i].u.c.chain; dump_multi (0, 0, cur_table, cur_ntable); return 1; } if (e->window == XtWindow (work_area)) { have_xy = 1; action_x = e->x; action_y = e->y; } else have_xy = 0; /* Parsing actions may not return until more user interaction happens, so remember which table we're scanning. */ my_table = cur_table; for (vi = 1; vi < my_table[i].u.a.node->c; vi++) if (resource_type (my_table[i].u.a.node->v[vi]) == 10) if (hid_parse_actions (my_table[i].u.a.node->v[vi].value)) break; cur_table = 0; return 1; }
/* deal with the "skip" subresource */ static void process_skips (Resource * res) { int type; int i, k; char *sval; int *cnt; char ***lst = NULL; if (res == NULL) return; for (i = 0; i < res->c; i++) { type = resource_type (res->v[i]); switch (type) { case 1: /* * an unnamed sub resource. This is something like * {refdes "J3"} */ sval = res->v[i].subres->v[0].value; if (sval == NULL) { Message ("Error: null skip value\n"); } else { if (NSTRCMP (sval, "refdes") == 0) { cnt = &n_refdes; lst = &ignore_refdes; } else if (NSTRCMP (sval, "value") == 0) { cnt = &n_value; lst = &ignore_value; } else if (NSTRCMP (sval, "descr") == 0) { cnt = &n_descr; lst = &ignore_descr; } else { cnt = NULL; } /* add the entry to the appropriate list */ if (cnt != NULL) { for (k = 1; k < res->v[i].subres->c; k++) { sval = res->v[i].subres->v[k].value; (*cnt)++; if ((*lst = (char **) realloc (*lst, (*cnt) * sizeof (char *))) == NULL) { fprintf (stderr, "realloc() failed\n"); exit (-1); } (*lst)[*cnt - 1] = strdup (sval); } } } break; default: Message (_("Ignored resource type = %d in skips= section\n"), type); } } }