hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/parisc/ccio-dma.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 ** ccio-dma.c:
34 ** DMA management routines for first generation cache-coherent machines.
....@@ -7,10 +8,6 @@
78 ** (c) Copyright 2000 Ryan Bradetich
89 ** (c) Copyright 2000 Hewlett-Packard Company
910 **
10
-** This program is free software; you can redistribute it and/or modify
11
-** it under the terms of the GNU General Public License as published by
12
-** the Free Software Foundation; either version 2 of the License, or
13
-** (at your option) any later version.
1411 **
1512 **
1613 ** "Real Mode" operation refers to U2/Uturn chip operation.
....@@ -42,6 +39,7 @@
4239 #include <linux/reboot.h>
4340 #include <linux/proc_fs.h>
4441 #include <linux/seq_file.h>
42
+#include <linux/dma-map-ops.h>
4543 #include <linux/scatterlist.h>
4644 #include <linux/iommu-helper.h>
4745 #include <linux/export.h>
....@@ -54,6 +52,8 @@
5452 #include <asm/io.h>
5553 #include <asm/hardware.h> /* for register_module() */
5654 #include <asm/parisc-device.h>
55
+
56
+#include "iommu.h"
5757
5858 /*
5959 ** Choose "ccio" since that's what HP-UX calls it.
....@@ -109,8 +109,6 @@
109109 #define IOA_NORMAL_MODE 0x00020080 /* IO_CONTROL to turn on CCIO */
110110 #define CMD_TLB_DIRECT_WRITE 35 /* IO_COMMAND for I/O TLB Writes */
111111 #define CMD_TLB_PURGE 33 /* IO_COMMAND to Purge I/O TLB entry */
112
-
113
-#define CCIO_MAPPING_ERROR (~(dma_addr_t)0)
114112
115113 struct ioa_registers {
116114 /* Runway Supervisory Set */
....@@ -359,8 +357,7 @@
359357 ** ggg sacrifices another 710 to the computer gods.
360358 */
361359
362
- boundary_size = ALIGN((unsigned long long)dma_get_seg_boundary(dev) + 1,
363
- 1ULL << IOVP_SHIFT) >> IOVP_SHIFT;
360
+ boundary_size = dma_get_seg_boundary_nr_pages(dev, IOVP_SHIFT);
364361
365362 if (pages_needed <= 8) {
366363 /*
....@@ -570,7 +567,7 @@
570567 ** "hints" parm includes the VALID bit!
571568 ** "dep" clobbers the physical address offset bits as well.
572569 */
573
- pa = virt_to_phys(vba);
570
+ pa = lpa(vba);
574571 asm volatile("depw %1,31,12,%0" : "+r" (pa) : "r" (hints));
575572 ((u32 *)pdir_ptr)[1] = (u32) pa;
576573
....@@ -607,14 +604,13 @@
607604 ** PCX-T'? Don't know. (eg C110 or similar K-class)
608605 **
609606 ** See PDC_MODEL/option 0/SW_CAP word for "Non-coherent IO-PDIR bit".
610
- ** Hopefully we can patch (NOP) these out at boot time somehow.
611607 **
612608 ** "Since PCX-U employs an offset hash that is incompatible with
613609 ** the real mode coherence index generation of U2, the PDIR entry
614610 ** must be flushed to memory to retain coherence."
615611 */
616
- asm volatile("fdc %%r0(%0)" : : "r" (pdir_ptr));
617
- asm volatile("sync");
612
+ asm_io_fdc(pdir_ptr);
613
+ asm_io_sync();
618614 }
619615
620616 /**
....@@ -680,17 +676,14 @@
680676 ** FIXME: PCX_W platforms don't need FDC/SYNC. (eg C360)
681677 ** PCX-U/U+ do. (eg C200/C240)
682678 ** See PDC_MODEL/option 0/SW_CAP for "Non-coherent IO-PDIR bit".
683
- **
684
- ** Hopefully someone figures out how to patch (NOP) the
685
- ** FDC/SYNC out at boot time.
686679 */
687
- asm volatile("fdc %%r0(%0)" : : "r" (pdir_ptr[7]));
680
+ asm_io_fdc(pdir_ptr);
688681
689682 iovp += IOVP_SIZE;
690683 byte_cnt -= IOVP_SIZE;
691684 }
692685
693
- asm volatile("sync");
686
+ asm_io_sync();
694687 ccio_clear_io_tlb(ioc, CCIO_IOVP(iova), saved_byte_cnt);
695688 }
696689
....@@ -714,8 +707,8 @@
714707 return 0;
715708 }
716709
717
- /* only support 32-bit devices (ie PCI/GSC) */
718
- return (int)(mask == 0xffffffffUL);
710
+ /* only support 32-bit or better devices (ie PCI/GSC) */
711
+ return (int)(mask >= 0xffffffffUL);
719712 }
720713
721714 /**
....@@ -742,7 +735,7 @@
742735 BUG_ON(!dev);
743736 ioc = GET_IOC(dev);
744737 if (!ioc)
745
- return CCIO_MAPPING_ERROR;
738
+ return DMA_MAPPING_ERROR;
746739
747740 BUG_ON(size <= 0);
748741
....@@ -1024,11 +1017,6 @@
10241017 DBG_RUN_SG("%s() DONE (nents %d)\n", __func__, nents);
10251018 }
10261019
1027
-static int ccio_mapping_error(struct device *dev, dma_addr_t dma_addr)
1028
-{
1029
- return dma_addr == CCIO_MAPPING_ERROR;
1030
-}
1031
-
10321020 static const struct dma_map_ops ccio_ops = {
10331021 .dma_supported = ccio_dma_supported,
10341022 .alloc = ccio_alloc,
....@@ -1037,7 +1025,9 @@
10371025 .unmap_page = ccio_unmap_page,
10381026 .map_sg = ccio_map_sg,
10391027 .unmap_sg = ccio_unmap_sg,
1040
- .mapping_error = ccio_mapping_error,
1028
+ .get_sgtable = dma_common_get_sgtable,
1029
+ .alloc_pages = dma_common_alloc_pages,
1030
+ .free_pages = dma_common_free_pages,
10411031 };
10421032
10431033 #ifdef CONFIG_PROC_FS
....@@ -1254,7 +1244,7 @@
12541244 ** Hot-Plug/Removal of PCI cards. (aka PCI OLARD).
12551245 */
12561246
1257
- iova_space_size = (u32) (totalram_pages / count_parisc_driver(&ccio_driver));
1247
+ iova_space_size = (u32) (totalram_pages() / count_parisc_driver(&ccio_driver));
12581248
12591249 /* limit IOVA space size to 1MB-1GB */
12601250
....@@ -1293,7 +1283,7 @@
12931283
12941284 DBG_INIT("%s() hpa 0x%p mem %luMB IOV %dMB (%d bits)\n",
12951285 __func__, ioc->ioc_regs,
1296
- (unsigned long) totalram_pages >> (20 - PAGE_SHIFT),
1286
+ (unsigned long) totalram_pages() >> (20 - PAGE_SHIFT),
12971287 iova_space_size>>20,
12981288 iov_order + PAGE_SHIFT);
12991289
....@@ -1390,15 +1380,17 @@
13901380 }
13911381 }
13921382
1393
-static void __init ccio_init_resources(struct ioc *ioc)
1383
+static int __init ccio_init_resources(struct ioc *ioc)
13941384 {
13951385 struct resource *res = ioc->mmio_region;
13961386 char *name = kmalloc(14, GFP_KERNEL);
1397
-
1387
+ if (unlikely(!name))
1388
+ return -ENOMEM;
13981389 snprintf(name, 14, "GSC Bus [%d/]", ioc->hw_path);
13991390
14001391 ccio_init_resource(res, name, &ioc->ioc_regs->io_io_low);
14011392 ccio_init_resource(res + 1, name, &ioc->ioc_regs->io_io_low_hv);
1393
+ return 0;
14021394 }
14031395
14041396 static int new_ioc_area(struct resource *res, unsigned long size,
....@@ -1528,6 +1520,7 @@
15281520 {
15291521 int i;
15301522 struct ioc *ioc, **ioc_p = &ioc_list;
1523
+ struct pci_hba_data *hba;
15311524
15321525 ioc = kzalloc(sizeof(struct ioc), GFP_KERNEL);
15331526 if (ioc == NULL) {
....@@ -1546,19 +1539,25 @@
15461539 *ioc_p = ioc;
15471540
15481541 ioc->hw_path = dev->hw_path;
1549
- ioc->ioc_regs = ioremap_nocache(dev->hpa.start, 4096);
1542
+ ioc->ioc_regs = ioremap(dev->hpa.start, 4096);
15501543 if (!ioc->ioc_regs) {
15511544 kfree(ioc);
15521545 return -ENOMEM;
15531546 }
15541547 ccio_ioc_init(ioc);
1555
- ccio_init_resources(ioc);
1548
+ if (ccio_init_resources(ioc)) {
1549
+ iounmap(ioc->ioc_regs);
1550
+ kfree(ioc);
1551
+ return -ENOMEM;
1552
+ }
15561553 hppa_dma_ops = &ccio_ops;
1557
- dev->dev.platform_data = kzalloc(sizeof(struct pci_hba_data), GFP_KERNEL);
15581554
1555
+ hba = kzalloc(sizeof(*hba), GFP_KERNEL);
15591556 /* if this fails, no I/O cards will work, so may as well bug */
1560
- BUG_ON(dev->dev.platform_data == NULL);
1561
- HBA_DATA(dev->dev.platform_data)->iommu = ioc;
1557
+ BUG_ON(hba == NULL);
1558
+
1559
+ hba->iommu = ioc;
1560
+ dev->dev.platform_data = hba;
15621561
15631562 #ifdef CONFIG_PROC_FS
15641563 if (ioc_count == 0) {