Exemplo n.º 1
0
ACPI_STATUS
acpi_ev_install_default_address_space_handlers (
	void)
{
	ACPI_STATUS             status;


	/*
	 * All address spaces (PCI Config, EC, SMBus) are scope dependent
	 * and registration must occur for a specific device.  In the case
	 * system memory and IO address spaces there is currently no device
	 * associated with the address space.  For these we use the root.
	 * We install the default PCI config space handler at the root so
	 * that this space is immediately available even though the we have
	 * not enumerated all the PCI Root Buses yet.  This is to conform
	 * to the ACPI specification which states that the PCI config
	 * space must be always available -- even though we are nowhere
	 * near ready to find the PCI root buses at this point.
	 *
	 * NOTE: We ignore AE_EXIST because this means that a handler has
	 * already been installed (via Acpi_install_address_space_handler)
	 */

	status = acpi_install_address_space_handler (acpi_gbl_root_node,
			   ADDRESS_SPACE_SYSTEM_MEMORY,
			   ACPI_DEFAULT_HANDLER, NULL, NULL);
	if ((ACPI_FAILURE (status)) &&
		(status != AE_EXIST))
	{
		return (status);
	}

	status = acpi_install_address_space_handler (acpi_gbl_root_node,
			   ADDRESS_SPACE_SYSTEM_IO,
			   ACPI_DEFAULT_HANDLER, NULL, NULL);
	if ((ACPI_FAILURE (status)) &&
		(status != AE_EXIST))
	{
		return (status);
	}

	status = acpi_install_address_space_handler (acpi_gbl_root_node,
			   ADDRESS_SPACE_PCI_CONFIG,
			   ACPI_DEFAULT_HANDLER, NULL, NULL);
	if ((ACPI_FAILURE (status)) &&
		(status != AE_EXIST))
	{
		return (status);
	}


	return (AE_OK);
}
Exemplo n.º 2
0
int acpi_i2c_install_space_handler(struct i2c_adapter *adapter)
{
	acpi_handle handle = ACPI_HANDLE(adapter->dev.parent);
	struct acpi_i2c_handler_data *data;
	acpi_status status;

	if (!handle)
		return -ENODEV;

	data = kzalloc(sizeof(struct acpi_i2c_handler_data),
			    GFP_KERNEL);
	if (!data)
		return -ENOMEM;

	data->adapter = adapter;
	status = acpi_bus_attach_private_data(handle, (void *)data);
	if (ACPI_FAILURE(status)) {
		kfree(data);
		return -ENOMEM;
	}

	status = acpi_install_address_space_handler(handle,
				ACPI_ADR_SPACE_GSBUS,
				&acpi_i2c_space_handler,
				NULL,
				data);
	if (ACPI_FAILURE(status)) {
		dev_err(&adapter->dev, "Error installing i2c space handler\n");
		acpi_bus_detach_private_data(handle);
		kfree(data);
		return -ENOMEM;
	}

	return 0;
}
Exemplo n.º 3
0
acpi_status
acpi_ev_init_address_spaces (
	void) {
	acpi_status                     status;
	acpi_native_uint                i;


	ACPI_FUNCTION_TRACE ("ev_init_address_spaces");


	/*
	 * All address spaces (PCI Config, EC, SMBus) are scope dependent
	 * and registration must occur for a specific device.
	 *
	 * In the case of the system memory and IO address spaces there is currently
	 * no device associated with the address space.  For these we use the root.
	 *
	 * We install the default PCI config space handler at the root so
	 * that this space is immediately available even though the we have
	 * not enumerated all the PCI Root Buses yet.  This is to conform
	 * to the ACPI specification which states that the PCI config
	 * space must be always available -- even though we are nowhere
	 * near ready to find the PCI root buses at this point.
	 *
	 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
	 * has already been installed (via acpi_install_address_space_handler).
	 * Similar for AE_SAME_HANDLER.
	 */

	for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
		status = acpi_install_address_space_handler ((acpi_handle) acpi_gbl_root_node,
				  acpi_gbl_default_address_spaces[i],
				  ACPI_DEFAULT_HANDLER, NULL, NULL);
		switch (status) {
		case AE_OK:
		case AE_SAME_HANDLER:
		case AE_ALREADY_EXISTS:

			/* These exceptions are all OK */

			break;

		default:

			return_ACPI_STATUS (status);
		}
	}

	return_ACPI_STATUS (AE_OK);
}
Exemplo n.º 4
0
static int atlas_acpi_button_add(struct acpi_device *device)
{
    acpi_status status;
    int i;
    int err;

    input_dev = input_allocate_device();
    if (!input_dev) {
        printk(KERN_ERR "atlas: unable to allocate input device\n");
        return -ENOMEM;
    }

    input_dev->name = "Atlas ACPI button driver";
    input_dev->phys = "ASIM0000/atlas/input0";
    input_dev->id.bustype = BUS_HOST;
    input_dev->keycode = atlas_keymap;
    input_dev->keycodesize = sizeof(unsigned short);
    input_dev->keycodemax = ARRAY_SIZE(atlas_keymap);

    input_set_capability(input_dev, EV_MSC, MSC_SCAN);
    __set_bit(EV_KEY, input_dev->evbit);
    for (i = 0; i < ARRAY_SIZE(atlas_keymap); i++) {
        if (i < 9) {
            atlas_keymap[i] = KEY_F1 + i;
            __set_bit(KEY_F1 + i, input_dev->keybit);
        } else
            atlas_keymap[i] = KEY_RESERVED;
    }

    err = input_register_device(input_dev);
    if (err) {
        printk(KERN_ERR "atlas: couldn't register input device\n");
        input_free_device(input_dev);
        return err;
    }

    /* hookup button handler */
    status = acpi_install_address_space_handler(device->handle,
                0x81, &acpi_atlas_button_handler,
                &acpi_atlas_button_setup, device);
    if (ACPI_FAILURE(status)) {
        printk(KERN_ERR "Atlas: Error installing addr spc handler\n");
        input_unregister_device(input_dev);
        status = -EINVAL;
    }

    return status;
}
Exemplo n.º 5
0
static int acpi_install_cmos_rtc_space_handler(struct acpi_device *adev,
		const struct acpi_device_id *id)
{
	acpi_status status;

	status = acpi_install_address_space_handler(adev->handle,
			ACPI_ADR_SPACE_CMOS,
			&acpi_cmos_rtc_space_handler,
			NULL, NULL);
	if (ACPI_FAILURE(status)) {
		pr_err(PREFIX "Error installing CMOS-RTC region handler\n");
		return -ENODEV;
	}

	return 1;
}
Exemplo n.º 6
0
acpi_status
ec_install_space_handler (
	EC_CONTEXT              *ec)
{
	acpi_status             status = AE_OK;

	FUNCTION_TRACE("ec_install_space_handler");

	if (!ec) {
		return_ACPI_STATUS(AE_BAD_PARAMETER);
	}

	status = acpi_install_address_space_handler (ec->acpi_handle,
		ACPI_ADR_SPACE_EC, &ec_space_handler, &ec_space_setup, ec);
	
	return_ACPI_STATUS(status);
}
Exemplo n.º 7
0
static int atlas_acpi_button_add(struct acpi_device *device)
{
	acpi_status status;
	int err;

	input_dev = input_allocate_device();
	if (!input_dev) {
		printk(KERN_ERR "atlas: unable to allocate input device\n");
		return -ENOMEM;
	}

	input_dev->name = "Atlas ACPI button driver";
	input_dev->phys = "ASIM0000/atlas/input0";
	input_dev->id.bustype = BUS_HOST;
	input_dev->evbit[BIT_WORD(EV_KEY)] = BIT_MASK(EV_KEY);

	set_bit(KEY_F1, input_dev->keybit);
	set_bit(KEY_F2, input_dev->keybit);
	set_bit(KEY_F3, input_dev->keybit);
	set_bit(KEY_F4, input_dev->keybit);
	set_bit(KEY_F5, input_dev->keybit);
	set_bit(KEY_F6, input_dev->keybit);
	set_bit(KEY_F7, input_dev->keybit);
	set_bit(KEY_F8, input_dev->keybit);
	set_bit(KEY_F9, input_dev->keybit);

	err = input_register_device(input_dev);
	if (err) {
		printk(KERN_ERR "atlas: couldn't register input device\n");
		input_free_device(input_dev);
		return err;
	}

	/* hookup button handler */
	status = acpi_install_address_space_handler(device->handle,
				0x81, &acpi_atlas_button_handler,
				&acpi_atlas_button_setup, device);
	if (ACPI_FAILURE(status)) {
		printk(KERN_ERR "Atlas: Error installing addr spc handler\n");
		input_unregister_device(input_dev);
		status = -EINVAL;
	}

	return status;
}
Exemplo n.º 8
0
acpi_status
acpi_ev_pci_config_region_setup(acpi_handle handle,
				u32 function,
				void *handler_context, void **region_context)
{
	acpi_status status = AE_OK;
	acpi_integer pci_value;
	struct acpi_pci_id *pci_id = *region_context;
	union acpi_operand_object *handler_obj;
	struct acpi_namespace_node *parent_node;
	struct acpi_namespace_node *pci_root_node;
	union acpi_operand_object *region_obj =
	    (union acpi_operand_object *)handle;
	struct acpi_device_id object_hID;

	ACPI_FUNCTION_TRACE(ev_pci_config_region_setup);

	handler_obj = region_obj->region.handler;
	if (!handler_obj) {
		/*
		 * No installed handler. This shouldn't happen because the dispatch
		 * routine checks before we get here, but we check again just in case.
		 */
		ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
				  "Attempting to init a region %p, with no handler\n",
				  region_obj));
		return_ACPI_STATUS(AE_NOT_EXIST);
	}

	*region_context = NULL;
	if (function == ACPI_REGION_DEACTIVATE) {
		if (pci_id) {
			ACPI_FREE(pci_id);
		}
		return_ACPI_STATUS(status);
	}

	parent_node = acpi_ns_get_parent_node(region_obj->region.node);

	/*
	 * Get the _SEG and _BBN values from the device upon which the handler
	 * is installed.
	 *
	 * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
	 * This is the device the handler has been registered to handle.
	 */

	/*
	 * If the address_space.Node is still pointing to the root, we need
	 * to scan upward for a PCI Root bridge and re-associate the op_region
	 * handlers with that device.
	 */
	if (handler_obj->address_space.node == acpi_gbl_root_node) {

		/* Start search from the parent object */

		pci_root_node = parent_node;
		while (pci_root_node != acpi_gbl_root_node) {
			status =
			    acpi_ut_execute_HID(pci_root_node, &object_hID);
			if (ACPI_SUCCESS(status)) {
				/*
				 * Got a valid _HID string, check if this is a PCI root.
				 * New for ACPI 3.0: check for a PCI Express root also.
				 */
				if (!
				    (ACPI_STRNCMP
				     (object_hID.value, PCI_ROOT_HID_STRING,
				      sizeof(PCI_ROOT_HID_STRING))
				     ||
				     !(ACPI_STRNCMP
				       (object_hID.value,
					PCI_EXPRESS_ROOT_HID_STRING,
					sizeof(PCI_EXPRESS_ROOT_HID_STRING)))))
				{

					/* Install a handler for this PCI root bridge */

					status =
					    acpi_install_address_space_handler((acpi_handle) pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
					if (ACPI_FAILURE(status)) {
						if (status == AE_SAME_HANDLER) {
							/*
							 * It is OK if the handler is already installed on the root
							 * bridge.  Still need to return a context object for the
							 * new PCI_Config operation region, however.
							 */
							status = AE_OK;
						} else {
							ACPI_EXCEPTION((AE_INFO,
									status,
									"Could not install PciConfig handler for Root Bridge %4.4s",
									acpi_ut_get_node_name
									(pci_root_node)));
						}
					}
					break;
				}
			}

			pci_root_node = acpi_ns_get_parent_node(pci_root_node);
		}

		/* PCI root bridge not found, use namespace root node */
	} else {
		pci_root_node = handler_obj->address_space.node;
	}

	/*
	 * If this region is now initialized, we are done.
	 * (install_address_space_handler could have initialized it)
	 */
	if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
		return_ACPI_STATUS(AE_OK);
	}

	/* Region is still not initialized. Create a new context */

	pci_id = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pci_id));
	if (!pci_id) {
		return_ACPI_STATUS(AE_NO_MEMORY);
	}

	/*
	 * For PCI_Config space access, we need the segment, bus,
	 * device and function numbers.  Acquire them here.
	 */

	/*
	 * Get the PCI device and function numbers from the _ADR object
	 * contained in the parent's scope.
	 */
	status =
	    acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, parent_node,
					    &pci_value);

	/*
	 * The default is zero, and since the allocation above zeroed
	 * the data, just do nothing on failure.
	 */
	if (ACPI_SUCCESS(status)) {
		pci_id->device = ACPI_HIWORD(ACPI_LODWORD(pci_value));
		pci_id->function = ACPI_LOWORD(ACPI_LODWORD(pci_value));
	}

	/* The PCI segment number comes from the _SEG method */

	status =
	    acpi_ut_evaluate_numeric_object(METHOD_NAME__SEG, pci_root_node,
					    &pci_value);
	if (ACPI_SUCCESS(status)) {
		pci_id->segment = ACPI_LOWORD(pci_value);
	}

	/* The PCI bus number comes from the _BBN method */

	status =
	    acpi_ut_evaluate_numeric_object(METHOD_NAME__BBN, pci_root_node,
					    &pci_value);
	if (ACPI_SUCCESS(status)) {
		pci_id->bus = ACPI_LOWORD(pci_value);
	}

	/* Complete this device's pci_id */

	acpi_os_derive_pci_id(pci_root_node, region_obj->region.node, &pci_id);

	*region_context = pci_id;
	return_ACPI_STATUS(AE_OK);
}
Exemplo n.º 9
0
ACPI_STATUS
acpi_ev_pci_config_region_setup (
	ACPI_HANDLE             handle,
	u32                     function,
	void                    *handler_context,
	void                    **region_context)
{
	ACPI_STATUS             status = AE_OK;
	ACPI_INTEGER            temp;
	PCI_HANDLER_CONTEXT     *pci_context = *region_context;
	ACPI_OPERAND_OBJECT     *handler_obj;
	ACPI_NAMESPACE_NODE     *node;
	ACPI_OPERAND_OBJECT     *region_obj = (ACPI_OPERAND_OBJECT *) handle;
	DEVICE_ID               object_hID;

	handler_obj = region_obj->region.addr_handler;

	if (!handler_obj) {
		/*
		 *  No installed handler. This shouldn't happen because the dispatch
		 *  routine checks before we get here, but we check again just in case.
		 */
		return(AE_NOT_EXIST);
	}

	if (function == ACPI_REGION_DEACTIVATE) {
		if (pci_context) {
			acpi_cm_free (pci_context);
			*region_context = NULL;
		}

		return (status);
	}


	/* Create a new context */

	pci_context = acpi_cm_callocate (sizeof(PCI_HANDLER_CONTEXT));
	if (!pci_context) {
		return (AE_NO_MEMORY);
	}

	/*
	 *  For PCI Config space access, we have to pass the segment, bus,
	 *  device and function numbers.  This routine must acquire those.
	 */

	/*
	 *  First get device and function numbers from the _ADR object
	 *  in the parent's scope.
	 */
	ACPI_ASSERT(region_obj->region.node);

	node = acpi_ns_get_parent_object (region_obj->region.node);


	/* Acpi_evaluate the _ADR object */

	status = acpi_cm_evaluate_numeric_object (METHOD_NAME__ADR, node, &temp);
	/*
	 *  The default is zero, since the allocation above zeroed the data, just
	 *  do nothing on failures.
	 */
	if (ACPI_SUCCESS (status)) {
		/*
		 *  Got it..
		 */
		pci_context->dev_func = (u32) temp;
	}

	/*
	 *  Get the _SEG and _BBN values from the device upon which the handler
	 *  is installed.
	 *
	 *  We need to get the _SEG and _BBN objects relative to the PCI BUS device.
	 *  This is the device the handler has been registered to handle.
	 */

	/*
	 *  If the Addr_handler.Node is still pointing to the root, we need
	 *  to scan upward for a PCI Root bridge and re-associate the Op_region
	 *  handlers with that device.
	 */
	if (handler_obj->addr_handler.node == acpi_gbl_root_node) {
		/*
		 * Node is currently the parent object
		 */
		while (node != acpi_gbl_root_node) {
			status = acpi_cm_execute_HID(node, &object_hID);

			if (ACPI_SUCCESS (status)) {
				if (!(STRNCMP(object_hID.buffer, PCI_ROOT_HID_STRING,
						   sizeof (PCI_ROOT_HID_STRING))))
				{
					acpi_install_address_space_handler(node,
							   ADDRESS_SPACE_PCI_CONFIG,
							   ACPI_DEFAULT_HANDLER, NULL, NULL);

					break;
				}
			}

			node = acpi_ns_get_parent_object(node);
		}
	}
	else {
		node = handler_obj->addr_handler.node;
	}

	status = acpi_cm_evaluate_numeric_object (METHOD_NAME__SEG, node, &temp);
	if (ACPI_SUCCESS (status)) {
		/*
		 *  Got it..
		 */
		pci_context->seg = (u32) temp;
	}

	status = acpi_cm_evaluate_numeric_object (METHOD_NAME__BBN, node, &temp);
	if (ACPI_SUCCESS (status)) {
		/*
		 *  Got it..
		 */
		pci_context->bus = (u32) temp;
	}

	*region_context = pci_context;

	return (AE_OK);
}
Exemplo n.º 10
0
int intel_pmic_install_opregion_handler(struct device *dev, acpi_handle handle,
                                        struct regmap *regmap,
                                        struct intel_pmic_opregion_data *d)
{
    acpi_status status;
    struct intel_pmic_opregion *opregion;
    int ret;

    if (!dev || !regmap || !d)
        return -EINVAL;

    if (!handle)
        return -ENODEV;

    opregion = devm_kzalloc(dev, sizeof(*opregion), GFP_KERNEL);
    if (!opregion)
        return -ENOMEM;

    mutex_init(&opregion->lock);
    opregion->regmap = regmap;
    opregion->lpat_table = acpi_lpat_get_conversion_table(handle);

    status = acpi_install_address_space_handler(handle,
             PMIC_POWER_OPREGION_ID,
             intel_pmic_power_handler,
             NULL, opregion);
    if (ACPI_FAILURE(status)) {
        ret = -ENODEV;
        goto out_error;
    }

    status = acpi_install_address_space_handler(handle,
             PMIC_THERMAL_OPREGION_ID,
             intel_pmic_thermal_handler,
             NULL, opregion);
    if (ACPI_FAILURE(status)) {
        acpi_remove_address_space_handler(handle, PMIC_POWER_OPREGION_ID,
                                          intel_pmic_power_handler);
        ret = -ENODEV;
        goto out_remove_power_handler;
    }

    status = acpi_install_address_space_handler(handle,
             PMIC_REGS_OPREGION_ID, intel_pmic_regs_handler, NULL,
             opregion);
    if (ACPI_FAILURE(status)) {
        ret = -ENODEV;
        goto out_remove_thermal_handler;
    }

    opregion->data = d;
    return 0;

out_remove_thermal_handler:
    acpi_remove_address_space_handler(handle, PMIC_THERMAL_OPREGION_ID,
                                      intel_pmic_thermal_handler);

out_remove_power_handler:
    acpi_remove_address_space_handler(handle, PMIC_POWER_OPREGION_ID,
                                      intel_pmic_power_handler);

out_error:
    acpi_lpat_free_conversion_table(opregion->lpat_table);
    return ret;
}