Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * 8237A DMA controller suspend functions.
0004  *
0005  * Written by Pierre Ossman, 2005.
0006  */
0007 
0008 #include <linux/dmi.h>
0009 #include <linux/init.h>
0010 #include <linux/syscore_ops.h>
0011 
0012 #include <asm/dma.h>
0013 #include <asm/x86_init.h>
0014 
0015 /*
0016  * This module just handles suspend/resume issues with the
0017  * 8237A DMA controller (used for ISA and LPC).
0018  * Allocation is handled in kernel/dma.c and normal usage is
0019  * in asm/dma.h.
0020  */
0021 
0022 static void i8237A_resume(void)
0023 {
0024     unsigned long flags;
0025     int i;
0026 
0027     flags = claim_dma_lock();
0028 
0029     dma_outb(0, DMA1_RESET_REG);
0030     dma_outb(0, DMA2_RESET_REG);
0031 
0032     for (i = 0; i < 8; i++) {
0033         set_dma_addr(i, 0x000000);
0034         /* DMA count is a bit weird so this is not 0 */
0035         set_dma_count(i, 1);
0036     }
0037 
0038     /* Enable cascade DMA or channel 0-3 won't work */
0039     enable_dma(4);
0040 
0041     release_dma_lock(flags);
0042 }
0043 
0044 static struct syscore_ops i8237_syscore_ops = {
0045     .resume     = i8237A_resume,
0046 };
0047 
0048 static int __init i8237A_init_ops(void)
0049 {
0050     /*
0051      * From SKL PCH onwards, the legacy DMA device is removed in which the
0052      * I/O ports (81h-83h, 87h, 89h-8Bh, 8Fh) related to it are removed
0053      * as well. All removed ports must return 0xff for a inb() request.
0054      *
0055      * Note: DMA_PAGE_2 (port 0x81) should not be checked for detecting
0056      * the presence of DMA device since it may be used by BIOS to decode
0057      * LPC traffic for POST codes. Original LPC only decodes one byte of
0058      * port 0x80 but some BIOS may choose to enhance PCH LPC port 0x8x
0059      * decoding.
0060      */
0061     if (dma_inb(DMA_PAGE_0) == 0xFF)
0062         return -ENODEV;
0063 
0064     /*
0065      * It is not required to load this driver as newer SoC may not
0066      * support 8237 DMA or bus mastering from LPC. Platform firmware
0067      * must announce the support for such legacy devices via
0068      * ACPI_FADT_LEGACY_DEVICES field in FADT table.
0069      */
0070     if (x86_pnpbios_disabled() && dmi_get_bios_year() >= 2017)
0071         return -ENODEV;
0072 
0073     register_syscore_ops(&i8237_syscore_ops);
0074     return 0;
0075 }
0076 device_initcall(i8237A_init_ops);