Lines Matching +full:ipc +full:- +full:3

1 // SPDX-License-Identifier: GPL-2.0
3 * Driver for the Intel SCU IPC mechanism
5 * (C) Copyright 2008-2010,2015 Intel Corporation
9 * core through IPC mechanism which in turn messaging between IA core ad SCU.
10 * SCU has two IPC mechanism IPC-1 and IPC-2. IPC-1 is used between IA32 and
11 * SCU where IPC-2 is used between P-Unit and SCU. This driver delas with
12 * IPC-1 Driver provides an API for power control unit registers (e.g. MSIC)
29 /* IPC defines the following message types */
35 #define IPC_CMD_PCNTRL_M 2 /* Register read-modify-write */
38 * IPC register summary
40 * IPC register blocks are memory mapped at fixed address of PCI BAR 0.
41 * To read or write information to the SCU, driver writes to IPC-1 memory
42 * mapped registers. The following is the IPC mechanism
48 * the IPC-1 register block, causing an interrupt to the SCU
50 * 3. SCU firmware decodes this interrupt and IPC message and the appropriate
54 #define IPC_WWBUF_SIZE 20 /* IPC Write buffer Size */
55 #define IPC_RWBUF_SIZE 20 /* IPC Read buffer Size */
56 #define IPC_IOC 0x100 /* IPC command register IOC bit */
73 * IPC Write/Read Buffers:
90 * intel_scu_ipc_dev_get() - Get SCU IPC instance
92 * The recommended new API takes SCU IPC instance as parameter and this
94 * sure the driver providing the IPC functionality cannot be unloaded
99 * Returns %NULL if SCU IPC is not currently available.
106 get_device(&ipcdev->dev); in intel_scu_ipc_dev_get()
108 * Prevent the IPC provider from being unloaded while it in intel_scu_ipc_dev_get()
111 if (try_module_get(ipcdev->owner)) in intel_scu_ipc_dev_get()
114 put_device(&ipcdev->dev); in intel_scu_ipc_dev_get()
122 * intel_scu_ipc_dev_put() - Put SCU IPC instance
123 * @scu: SCU IPC instance
125 * This function releases the SCU IPC instance retrieved from
126 * intel_scu_ipc_dev_get() and allows the driver providing IPC to be
132 module_put(scu->owner); in intel_scu_ipc_dev_put()
133 put_device(&scu->dev); in intel_scu_ipc_dev_put()
145 struct intel_scu_ipc_dev *scu = dr->scu; in devm_intel_scu_ipc_dev_release()
151 * devm_intel_scu_ipc_dev_get() - Allocate managed SCU IPC device
152 * @dev: Device requesting the SCU IPC device
154 * The recommended new API takes SCU IPC instance as parameter and this
156 * sure the driver providing the IPC functionality cannot be unloaded
159 * Returns %NULL if SCU IPC is not currently available.
176 dr->scu = scu; in devm_intel_scu_ipc_dev_get()
184 * Send ipc command
188 * |rfu2(8) | size(8) | command id(4) | rfu1(3) | ioc(1) | command(8)|
192 reinit_completion(&scu->cmd_complete); in ipc_command()
193 writel(cmd | IPC_IOC, scu->ipc_base); in ipc_command()
197 * Write ipc data
198 * IPC Write Buffer (Write Only):
199 * 16-byte buffer for sending data associated with IPC command to
204 writel(data, scu->ipc_base + IPC_WRITE_BUFFER + offset); in ipc_data_writel()
209 * Driver will read this register to get the ready/busy status of the IPC
210 * block and error status of the IPC command that was just processed by SCU
216 return __raw_readl(scu->ipc_base + IPC_STATUS); in ipc_read_status()
219 /* Read ipc u32 data */
222 return readl(scu->ipc_base + IPC_READ_BUFFER + offset); in ipc_data_readl()
236 return (status & IPC_STATUS_ERR) ? -EIO : 0; in busy_loop()
239 /* Wait till ipc ioc interrupt is received or timeout in 10 HZ */
244 wait_for_completion_timeout(&scu->cmd_complete, IPC_TIMEOUT); in ipc_wait_for_interrupt()
248 return -ETIMEDOUT; in ipc_wait_for_interrupt()
251 return -EIO; in ipc_wait_for_interrupt()
258 return scu->data.irq > 0 ? ipc_wait_for_interrupt(scu) : busy_loop(scu); in intel_scu_ipc_check_status()
268 return ERR_PTR(-ENODEV); in intel_scu_ipc_get()
272 dev_dbg(&scu->dev, "device is busy\n"); in intel_scu_ipc_get()
273 return ERR_PTR(-EBUSY); in intel_scu_ipc_get()
311 ipc_command(scu, (count * 3) << 16 | id << 12 | 0 << 8 | op); in pwr_reg_rdwr()
332 * intel_scu_ipc_dev_ioread8() - Read a byte via the SCU
333 * @scu: Optional SCU IPC instance
349 * intel_scu_ipc_dev_iowrite8() - Write a byte via the SCU
350 * @scu: Optional SCU IPC instance
366 * intel_scu_ipc_dev_readv() - Read a set of registers
367 * @scu: Optional SCU IPC instance
387 * intel_scu_ipc_dev_writev() - Write a set of registers
388 * @scu: Optional SCU IPC instance
408 * intel_scu_ipc_dev_update() - Update a register
409 * @scu: Optional SCU IPC instance
414 * Read-modify-write power control unit register. The first data argument
431 * intel_scu_ipc_dev_simple_command() - Send a simple command
432 * @scu: Optional SCU IPC instance
459 dev_err(&scu->dev, "IPC command %#x failed with %d\n", cmdval, err); in intel_scu_ipc_dev_simple_command()
465 * intel_scu_ipc_dev_command_with_size() - Command with data
466 * @scu: Optional SCU IPC instance
471 * @size: Input size written to the IPC command register in whatever
490 return -EINVAL; in intel_scu_ipc_dev_command_with_size()
506 dev_err(&scu->dev, "IPC command %#x failed with %d\n", cmdval, err); in intel_scu_ipc_dev_command_with_size()
531 writel(status | IPC_STATUS_IRQ, scu->ipc_base + IPC_STATUS); in ioc()
532 complete(&scu->cmd_complete); in ioc()
540 struct intel_scu_ipc_data *data = &scu->data; in intel_scu_ipc_release()
542 if (data->irq > 0) in intel_scu_ipc_release()
543 free_irq(data->irq, scu); in intel_scu_ipc_release()
544 iounmap(scu->ipc_base); in intel_scu_ipc_release()
545 release_mem_region(data->mem.start, resource_size(&data->mem)); in intel_scu_ipc_release()
550 * __intel_scu_ipc_register() - Register SCU IPC device
552 * @scu_data: Data used to configure SCU IPC
553 * @owner: Module registering the SCU IPC device
555 * Call this function to register SCU IPC mechanism under @parent.
556 * Returns pointer to the new SCU IPC device or ERR_PTR() in case of
558 * SCU IPC calls itself.
572 /* We support only one IPC */ in __intel_scu_ipc_register()
574 return ERR_PTR(-EBUSY); in __intel_scu_ipc_register()
578 return ERR_PTR(-ENOMEM); in __intel_scu_ipc_register()
580 scu->owner = owner; in __intel_scu_ipc_register()
581 scu->dev.parent = parent; in __intel_scu_ipc_register()
582 scu->dev.class = &intel_scu_ipc_class; in __intel_scu_ipc_register()
583 scu->dev.release = intel_scu_ipc_release; in __intel_scu_ipc_register()
585 memcpy(&scu->data, scu_data, sizeof(scu->data)); in __intel_scu_ipc_register()
586 data = &scu->data; in __intel_scu_ipc_register()
588 if (!request_mem_region(data->mem.start, resource_size(&data->mem), "intel_scu_ipc")) { in __intel_scu_ipc_register()
589 err = -EBUSY; in __intel_scu_ipc_register()
593 ipc_base = ioremap(data->mem.start, resource_size(&data->mem)); in __intel_scu_ipc_register()
595 err = -ENOMEM; in __intel_scu_ipc_register()
599 scu->ipc_base = ipc_base; in __intel_scu_ipc_register()
600 init_completion(&scu->cmd_complete); in __intel_scu_ipc_register()
602 if (data->irq > 0) { in __intel_scu_ipc_register()
603 err = request_irq(data->irq, ioc, 0, "intel_scu_ipc", scu); in __intel_scu_ipc_register()
610 * releasing the SCU IPC resources once refcount drops to zero. in __intel_scu_ipc_register()
612 dev_set_name(&scu->dev, "intel_scu_ipc"); in __intel_scu_ipc_register()
613 err = device_register(&scu->dev); in __intel_scu_ipc_register()
615 put_device(&scu->dev); in __intel_scu_ipc_register()
626 release_mem_region(data->mem.start, resource_size(&data->mem)); in __intel_scu_ipc_register()
634 * intel_scu_ipc_unregister() - Unregister SCU IPC
635 * @scu: SCU IPC handle
637 * This unregisters the SCU IPC device and releases the acquired
646 device_unregister(&scu->dev); in intel_scu_ipc_unregister()
654 struct intel_scu_ipc_dev *scu = dr->scu; in devm_intel_scu_ipc_unregister()
660 * __devm_intel_scu_ipc_register() - Register managed SCU IPC device
662 * @scu_data: Data used to configure SCU IPC
663 * @owner: Module registering the SCU IPC device
665 * Call this function to register managed SCU IPC mechanism under
666 * @parent. Returns pointer to the new SCU IPC device or ERR_PTR() in
668 * to do SCU IPC calls itself.
688 dr->scu = scu; in __devm_intel_scu_ipc_register()