1 /* $Id: pci_iommu.c,v 1.17 2001/12/17 07:05:09 davem Exp $
2 * pci_iommu.c: UltraSparc PCI controller IOM/STC support.
4 * Copyright (C) 1999 David S. Miller (davem@redhat.com)
5 * Copyright (C) 1999, 2000 Jakub Jelinek (jakub@redhat.com)
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
11 #include <linux/delay.h>
15 #include "iommu_common.h"
17 #define PCI_STC_CTXMATCH_ADDR(STC, CTX) \
18 ((STC)->strbuf_ctxmatch_base + ((CTX) << 3))
20 /* Accessing IOMMU and Streaming Buffer registers.
21 * REG parameter is a physical address. All registers
22 * are 64-bits in size.
24 #define pci_iommu_read(__reg) \
26 __asm__ __volatile__("ldxa [%1] %2, %0" \
28 : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
32 #define pci_iommu_write(__reg, __val) \
33 __asm__ __volatile__("stxa %0, [%1] %2" \
35 : "r" (__val), "r" (__reg), \
36 "i" (ASI_PHYS_BYPASS_EC_E))
38 /* Must be invoked under the IOMMU lock. */
39 static void __iommu_flushall(struct pci_iommu *iommu)
44 tag = iommu->iommu_flush + (0xa580UL - 0x0210UL);
45 for (entry = 0; entry < 16; entry++) {
46 pci_iommu_write(tag, 0);
50 /* Ensure completion of previous PIO writes. */
51 (void) pci_iommu_read(iommu->write_complete_reg);
54 #define IOPTE_CONSISTENT(CTX) \
55 (IOPTE_VALID | IOPTE_CACHE | \
56 (((CTX) << 47) & IOPTE_CONTEXT))
58 #define IOPTE_STREAMING(CTX) \
59 (IOPTE_CONSISTENT(CTX) | IOPTE_STBUF)
61 /* Existing mappings are never marked invalid, instead they
62 * are pointed to a dummy page.
64 #define IOPTE_IS_DUMMY(iommu, iopte) \
65 ((iopte_val(*iopte) & IOPTE_PAGE) == (iommu)->dummy_page_pa)
67 static void inline iopte_make_dummy(struct pci_iommu *iommu, iopte_t *iopte)
69 unsigned long val = iopte_val(*iopte);
72 val |= iommu->dummy_page_pa;
74 iopte_val(*iopte) = val;
77 /* Based largely upon the ppc64 iommu allocator. */
78 static long pci_arena_alloc(struct pci_iommu *iommu, unsigned long npages)
80 struct pci_iommu_arena *arena = &iommu->arena;
81 unsigned long n, i, start, end, limit;
89 n = find_next_zero_bit(arena->map, limit, start);
91 if (unlikely(end >= limit)) {
92 if (likely(pass < 1)) {
95 __iommu_flushall(iommu);
99 /* Scanned the whole thing, give up. */
104 for (i = n; i < end; i++) {
105 if (test_bit(i, arena->map)) {
111 for (i = n; i < end; i++)
112 __set_bit(i, arena->map);
119 static void pci_arena_free(struct pci_iommu_arena *arena, unsigned long base, unsigned long npages)
123 for (i = base; i < (base + npages); i++)
124 __clear_bit(i, arena->map);
127 void pci_iommu_table_init(struct pci_iommu *iommu, int tsbsize, u32 dma_offset, u32 dma_addr_mask)
129 unsigned long i, tsbbase, order, sz, num_tsb_entries;
131 num_tsb_entries = tsbsize / sizeof(iopte_t);
133 /* Setup initial software IOMMU state. */
134 spin_lock_init(&iommu->lock);
135 iommu->ctx_lowest_free = 1;
136 iommu->page_table_map_base = dma_offset;
137 iommu->dma_addr_mask = dma_addr_mask;
139 /* Allocate and initialize the free area map. */
140 sz = num_tsb_entries / 8;
141 sz = (sz + 7UL) & ~7UL;
142 iommu->arena.map = kmalloc(sz, GFP_KERNEL);
143 if (!iommu->arena.map) {
144 prom_printf("PCI_IOMMU: Error, kmalloc(arena.map) failed.\n");
147 memset(iommu->arena.map, 0, sz);
148 iommu->arena.limit = num_tsb_entries;
150 /* Allocate and initialize the dummy page which we
151 * set inactive IO PTEs to point to.
153 iommu->dummy_page = __get_free_pages(GFP_KERNEL, 0);
154 if (!iommu->dummy_page) {
155 prom_printf("PCI_IOMMU: Error, gfp(dummy_page) failed.\n");
158 memset((void *)iommu->dummy_page, 0, PAGE_SIZE);
159 iommu->dummy_page_pa = (unsigned long) __pa(iommu->dummy_page);
161 /* Now allocate and setup the IOMMU page table itself. */
162 order = get_order(tsbsize);
163 tsbbase = __get_free_pages(GFP_KERNEL, order);
165 prom_printf("PCI_IOMMU: Error, gfp(tsb) failed.\n");
168 iommu->page_table = (iopte_t *)tsbbase;
170 for (i = 0; i < num_tsb_entries; i++)
171 iopte_make_dummy(iommu, &iommu->page_table[i]);
174 static inline iopte_t *alloc_npages(struct pci_iommu *iommu, unsigned long npages)
178 entry = pci_arena_alloc(iommu, npages);
179 if (unlikely(entry < 0))
182 return iommu->page_table + entry;
185 static inline void free_npages(struct pci_iommu *iommu, dma_addr_t base, unsigned long npages)
187 pci_arena_free(&iommu->arena, base >> IO_PAGE_SHIFT, npages);
190 static int iommu_alloc_ctx(struct pci_iommu *iommu)
192 int lowest = iommu->ctx_lowest_free;
193 int sz = IOMMU_NUM_CTXS - lowest;
194 int n = find_next_zero_bit(iommu->ctx_bitmap, sz, lowest);
196 if (unlikely(n == sz)) {
197 n = find_next_zero_bit(iommu->ctx_bitmap, lowest, 1);
198 if (unlikely(n == lowest)) {
199 printk(KERN_WARNING "IOMMU: Ran out of contexts.\n");
204 __set_bit(n, iommu->ctx_bitmap);
209 static inline void iommu_free_ctx(struct pci_iommu *iommu, int ctx)
212 __clear_bit(ctx, iommu->ctx_bitmap);
213 if (ctx < iommu->ctx_lowest_free)
214 iommu->ctx_lowest_free = ctx;
218 /* Allocate and map kernel buffer of size SIZE using consistent mode
219 * DMA for PCI device PDEV. Return non-NULL cpu-side address if
220 * successful and set *DMA_ADDRP to the PCI side dma address.
222 static void *pci_4u_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr_t *dma_addrp)
224 struct pcidev_cookie *pcp;
225 struct pci_iommu *iommu;
227 unsigned long flags, order, first_page;
231 size = IO_PAGE_ALIGN(size);
232 order = get_order(size);
236 first_page = __get_free_pages(GFP_ATOMIC, order);
237 if (first_page == 0UL)
239 memset((char *)first_page, 0, PAGE_SIZE << order);
242 iommu = pcp->pbm->iommu;
244 spin_lock_irqsave(&iommu->lock, flags);
245 iopte = alloc_npages(iommu, size >> IO_PAGE_SHIFT);
246 spin_unlock_irqrestore(&iommu->lock, flags);
248 if (unlikely(iopte == NULL)) {
249 free_pages(first_page, order);
253 *dma_addrp = (iommu->page_table_map_base +
254 ((iopte - iommu->page_table) << IO_PAGE_SHIFT));
255 ret = (void *) first_page;
256 npages = size >> IO_PAGE_SHIFT;
257 first_page = __pa(first_page);
259 iopte_val(*iopte) = (IOPTE_CONSISTENT(0UL) |
261 (first_page & IOPTE_PAGE));
263 first_page += IO_PAGE_SIZE;
269 /* Free and unmap a consistent DMA translation. */
270 static void pci_4u_free_consistent(struct pci_dev *pdev, size_t size, void *cpu, dma_addr_t dvma)
272 struct pcidev_cookie *pcp;
273 struct pci_iommu *iommu;
275 unsigned long flags, order, npages;
277 npages = IO_PAGE_ALIGN(size) >> IO_PAGE_SHIFT;
279 iommu = pcp->pbm->iommu;
280 iopte = iommu->page_table +
281 ((dvma - iommu->page_table_map_base) >> IO_PAGE_SHIFT);
283 spin_lock_irqsave(&iommu->lock, flags);
285 free_npages(iommu, dvma, npages);
287 spin_unlock_irqrestore(&iommu->lock, flags);
289 order = get_order(size);
291 free_pages((unsigned long)cpu, order);
294 /* Map a single buffer at PTR of SZ bytes for PCI DMA
297 static dma_addr_t pci_4u_map_single(struct pci_dev *pdev, void *ptr, size_t sz, int direction)
299 struct pcidev_cookie *pcp;
300 struct pci_iommu *iommu;
301 struct pci_strbuf *strbuf;
303 unsigned long flags, npages, oaddr;
304 unsigned long i, base_paddr, ctx;
306 unsigned long iopte_protection;
309 iommu = pcp->pbm->iommu;
310 strbuf = &pcp->pbm->stc;
312 if (unlikely(direction == PCI_DMA_NONE))
315 oaddr = (unsigned long)ptr;
316 npages = IO_PAGE_ALIGN(oaddr + sz) - (oaddr & IO_PAGE_MASK);
317 npages >>= IO_PAGE_SHIFT;
319 spin_lock_irqsave(&iommu->lock, flags);
320 base = alloc_npages(iommu, npages);
322 if (iommu->iommu_ctxflush)
323 ctx = iommu_alloc_ctx(iommu);
324 spin_unlock_irqrestore(&iommu->lock, flags);
329 bus_addr = (iommu->page_table_map_base +
330 ((base - iommu->page_table) << IO_PAGE_SHIFT));
331 ret = bus_addr | (oaddr & ~IO_PAGE_MASK);
332 base_paddr = __pa(oaddr & IO_PAGE_MASK);
333 if (strbuf->strbuf_enabled)
334 iopte_protection = IOPTE_STREAMING(ctx);
336 iopte_protection = IOPTE_CONSISTENT(ctx);
337 if (direction != PCI_DMA_TODEVICE)
338 iopte_protection |= IOPTE_WRITE;
340 for (i = 0; i < npages; i++, base++, base_paddr += IO_PAGE_SIZE)
341 iopte_val(*base) = iopte_protection | base_paddr;
346 iommu_free_ctx(iommu, ctx);
348 if (printk_ratelimit())
350 return PCI_DMA_ERROR_CODE;
353 static void pci_strbuf_flush(struct pci_strbuf *strbuf, struct pci_iommu *iommu, u32 vaddr, unsigned long ctx, unsigned long npages, int direction)
357 if (strbuf->strbuf_ctxflush &&
358 iommu->iommu_ctxflush) {
359 unsigned long matchreg, flushreg;
362 flushreg = strbuf->strbuf_ctxflush;
363 matchreg = PCI_STC_CTXMATCH_ADDR(strbuf, ctx);
365 pci_iommu_write(flushreg, ctx);
366 val = pci_iommu_read(matchreg);
373 pci_iommu_write(flushreg, ctx);
376 val = pci_iommu_read(matchreg);
378 printk(KERN_WARNING "pci_strbuf_flush: ctx flush "
379 "timeout matchreg[%lx] ctx[%lx]\n",
387 for (i = 0; i < npages; i++, vaddr += IO_PAGE_SIZE)
388 pci_iommu_write(strbuf->strbuf_pflush, vaddr);
392 /* If the device could not have possibly put dirty data into
393 * the streaming cache, no flush-flag synchronization needs
396 if (direction == PCI_DMA_TODEVICE)
399 PCI_STC_FLUSHFLAG_INIT(strbuf);
400 pci_iommu_write(strbuf->strbuf_fsync, strbuf->strbuf_flushflag_pa);
401 (void) pci_iommu_read(iommu->write_complete_reg);
404 while (!PCI_STC_FLUSHFLAG_SET(strbuf)) {
412 printk(KERN_WARNING "pci_strbuf_flush: flushflag timeout "
413 "vaddr[%08x] ctx[%lx] npages[%ld]\n",
417 /* Unmap a single streaming mode DMA translation. */
418 static void pci_4u_unmap_single(struct pci_dev *pdev, dma_addr_t bus_addr, size_t sz, int direction)
420 struct pcidev_cookie *pcp;
421 struct pci_iommu *iommu;
422 struct pci_strbuf *strbuf;
424 unsigned long flags, npages, ctx, i;
426 if (unlikely(direction == PCI_DMA_NONE)) {
427 if (printk_ratelimit())
433 iommu = pcp->pbm->iommu;
434 strbuf = &pcp->pbm->stc;
436 npages = IO_PAGE_ALIGN(bus_addr + sz) - (bus_addr & IO_PAGE_MASK);
437 npages >>= IO_PAGE_SHIFT;
438 base = iommu->page_table +
439 ((bus_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT);
440 #ifdef DEBUG_PCI_IOMMU
441 if (IOPTE_IS_DUMMY(iommu, base))
442 printk("pci_unmap_single called on non-mapped region %08x,%08x from %016lx\n",
443 bus_addr, sz, __builtin_return_address(0));
445 bus_addr &= IO_PAGE_MASK;
447 spin_lock_irqsave(&iommu->lock, flags);
449 /* Record the context, if any. */
451 if (iommu->iommu_ctxflush)
452 ctx = (iopte_val(*base) & IOPTE_CONTEXT) >> 47UL;
454 /* Step 1: Kick data out of streaming buffers if necessary. */
455 if (strbuf->strbuf_enabled)
456 pci_strbuf_flush(strbuf, iommu, bus_addr, ctx,
459 /* Step 2: Clear out TSB entries. */
460 for (i = 0; i < npages; i++)
461 iopte_make_dummy(iommu, base + i);
463 free_npages(iommu, bus_addr - iommu->page_table_map_base, npages);
465 iommu_free_ctx(iommu, ctx);
467 spin_unlock_irqrestore(&iommu->lock, flags);
470 #define SG_ENT_PHYS_ADDRESS(SG) \
471 (__pa(page_address((SG)->page)) + (SG)->offset)
473 static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg,
474 int nused, int nelems, unsigned long iopte_protection)
476 struct scatterlist *dma_sg = sg;
477 struct scatterlist *sg_end = sg + nelems;
480 for (i = 0; i < nused; i++) {
481 unsigned long pteval = ~0UL;
484 dma_npages = ((dma_sg->dma_address & (IO_PAGE_SIZE - 1UL)) +
486 ((IO_PAGE_SIZE - 1UL))) >> IO_PAGE_SHIFT;
488 unsigned long offset;
491 /* If we are here, we know we have at least one
492 * more page to map. So walk forward until we
493 * hit a page crossing, and begin creating new
494 * mappings from that spot.
499 tmp = SG_ENT_PHYS_ADDRESS(sg);
501 if (((tmp ^ pteval) >> IO_PAGE_SHIFT) != 0UL) {
502 pteval = tmp & IO_PAGE_MASK;
503 offset = tmp & (IO_PAGE_SIZE - 1UL);
506 if (((tmp ^ (tmp + len - 1UL)) >> IO_PAGE_SHIFT) != 0UL) {
507 pteval = (tmp + IO_PAGE_SIZE) & IO_PAGE_MASK;
509 len -= (IO_PAGE_SIZE - (tmp & (IO_PAGE_SIZE - 1UL)));
515 pteval = iopte_protection | (pteval & IOPTE_PAGE);
517 *iopte++ = __iopte(pteval);
518 pteval += IO_PAGE_SIZE;
519 len -= (IO_PAGE_SIZE - offset);
524 pteval = (pteval & IOPTE_PAGE) + len;
527 /* Skip over any tail mappings we've fully mapped,
528 * adjusting pteval along the way. Stop when we
529 * detect a page crossing event.
531 while (sg < sg_end &&
532 (pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
533 (pteval == SG_ENT_PHYS_ADDRESS(sg)) &&
535 (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
536 pteval += sg->length;
539 if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL)
541 } while (dma_npages != 0);
546 /* Map a set of buffers described by SGLIST with NELEMS array
547 * elements in streaming mode for PCI DMA.
548 * When making changes here, inspect the assembly output. I was having
549 * hard time to kepp this routine out of using stack slots for holding variables.
551 static int pci_4u_map_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int direction)
553 struct pcidev_cookie *pcp;
554 struct pci_iommu *iommu;
555 struct pci_strbuf *strbuf;
556 unsigned long flags, ctx, npages, iopte_protection;
559 struct scatterlist *sgtmp;
562 /* Fast path single entry scatterlists. */
564 sglist->dma_address =
565 pci_4u_map_single(pdev,
566 (page_address(sglist->page) + sglist->offset),
567 sglist->length, direction);
568 if (unlikely(sglist->dma_address == PCI_DMA_ERROR_CODE))
570 sglist->dma_length = sglist->length;
575 iommu = pcp->pbm->iommu;
576 strbuf = &pcp->pbm->stc;
578 if (unlikely(direction == PCI_DMA_NONE))
581 /* Step 1: Prepare scatter list. */
583 npages = prepare_sg(sglist, nelems);
585 /* Step 2: Allocate a cluster and context, if necessary. */
587 spin_lock_irqsave(&iommu->lock, flags);
589 base = alloc_npages(iommu, npages);
591 if (iommu->iommu_ctxflush)
592 ctx = iommu_alloc_ctx(iommu);
594 spin_unlock_irqrestore(&iommu->lock, flags);
599 dma_base = iommu->page_table_map_base +
600 ((base - iommu->page_table) << IO_PAGE_SHIFT);
602 /* Step 3: Normalize DMA addresses. */
606 while (used && sgtmp->dma_length) {
607 sgtmp->dma_address += dma_base;
611 used = nelems - used;
613 /* Step 4: Create the mappings. */
614 if (strbuf->strbuf_enabled)
615 iopte_protection = IOPTE_STREAMING(ctx);
617 iopte_protection = IOPTE_CONSISTENT(ctx);
618 if (direction != PCI_DMA_TODEVICE)
619 iopte_protection |= IOPTE_WRITE;
621 fill_sg(base, sglist, used, nelems, iopte_protection);
624 verify_sglist(sglist, nelems, base, npages);
630 iommu_free_ctx(iommu, ctx);
632 if (printk_ratelimit())
637 /* Unmap a set of streaming mode DMA translations. */
638 static void pci_4u_unmap_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int direction)
640 struct pcidev_cookie *pcp;
641 struct pci_iommu *iommu;
642 struct pci_strbuf *strbuf;
644 unsigned long flags, ctx, i, npages;
647 if (unlikely(direction == PCI_DMA_NONE)) {
648 if (printk_ratelimit())
653 iommu = pcp->pbm->iommu;
654 strbuf = &pcp->pbm->stc;
656 bus_addr = sglist->dma_address & IO_PAGE_MASK;
658 for (i = 1; i < nelems; i++)
659 if (sglist[i].dma_length == 0)
662 npages = (IO_PAGE_ALIGN(sglist[i].dma_address + sglist[i].dma_length) -
663 bus_addr) >> IO_PAGE_SHIFT;
665 base = iommu->page_table +
666 ((bus_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT);
668 #ifdef DEBUG_PCI_IOMMU
669 if (IOPTE_IS_DUMMY(iommu, base))
670 printk("pci_unmap_sg called on non-mapped region %016lx,%d from %016lx\n", sglist->dma_address, nelems, __builtin_return_address(0));
673 spin_lock_irqsave(&iommu->lock, flags);
675 /* Record the context, if any. */
677 if (iommu->iommu_ctxflush)
678 ctx = (iopte_val(*base) & IOPTE_CONTEXT) >> 47UL;
680 /* Step 1: Kick data out of streaming buffers if necessary. */
681 if (strbuf->strbuf_enabled)
682 pci_strbuf_flush(strbuf, iommu, bus_addr, ctx, npages, direction);
684 /* Step 2: Clear out the TSB entries. */
685 for (i = 0; i < npages; i++)
686 iopte_make_dummy(iommu, base + i);
688 free_npages(iommu, bus_addr - iommu->page_table_map_base, npages);
690 iommu_free_ctx(iommu, ctx);
692 spin_unlock_irqrestore(&iommu->lock, flags);
695 /* Make physical memory consistent for a single
696 * streaming mode DMA translation after a transfer.
698 static void pci_4u_dma_sync_single_for_cpu(struct pci_dev *pdev, dma_addr_t bus_addr, size_t sz, int direction)
700 struct pcidev_cookie *pcp;
701 struct pci_iommu *iommu;
702 struct pci_strbuf *strbuf;
703 unsigned long flags, ctx, npages;
706 iommu = pcp->pbm->iommu;
707 strbuf = &pcp->pbm->stc;
709 if (!strbuf->strbuf_enabled)
712 spin_lock_irqsave(&iommu->lock, flags);
714 npages = IO_PAGE_ALIGN(bus_addr + sz) - (bus_addr & IO_PAGE_MASK);
715 npages >>= IO_PAGE_SHIFT;
716 bus_addr &= IO_PAGE_MASK;
718 /* Step 1: Record the context, if any. */
720 if (iommu->iommu_ctxflush &&
721 strbuf->strbuf_ctxflush) {
724 iopte = iommu->page_table +
725 ((bus_addr - iommu->page_table_map_base)>>IO_PAGE_SHIFT);
726 ctx = (iopte_val(*iopte) & IOPTE_CONTEXT) >> 47UL;
729 /* Step 2: Kick data out of streaming buffers. */
730 pci_strbuf_flush(strbuf, iommu, bus_addr, ctx, npages, direction);
732 spin_unlock_irqrestore(&iommu->lock, flags);
735 /* Make physical memory consistent for a set of streaming
736 * mode DMA translations after a transfer.
738 static void pci_4u_dma_sync_sg_for_cpu(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int direction)
740 struct pcidev_cookie *pcp;
741 struct pci_iommu *iommu;
742 struct pci_strbuf *strbuf;
743 unsigned long flags, ctx, npages, i;
747 iommu = pcp->pbm->iommu;
748 strbuf = &pcp->pbm->stc;
750 if (!strbuf->strbuf_enabled)
753 spin_lock_irqsave(&iommu->lock, flags);
755 /* Step 1: Record the context, if any. */
757 if (iommu->iommu_ctxflush &&
758 strbuf->strbuf_ctxflush) {
761 iopte = iommu->page_table +
762 ((sglist[0].dma_address - iommu->page_table_map_base) >> IO_PAGE_SHIFT);
763 ctx = (iopte_val(*iopte) & IOPTE_CONTEXT) >> 47UL;
766 /* Step 2: Kick data out of streaming buffers. */
767 bus_addr = sglist[0].dma_address & IO_PAGE_MASK;
768 for(i = 1; i < nelems; i++)
769 if (!sglist[i].dma_length)
772 npages = (IO_PAGE_ALIGN(sglist[i].dma_address + sglist[i].dma_length)
773 - bus_addr) >> IO_PAGE_SHIFT;
774 pci_strbuf_flush(strbuf, iommu, bus_addr, ctx, npages, direction);
776 spin_unlock_irqrestore(&iommu->lock, flags);
779 struct pci_iommu_ops pci_sun4u_iommu_ops = {
780 .alloc_consistent = pci_4u_alloc_consistent,
781 .free_consistent = pci_4u_free_consistent,
782 .map_single = pci_4u_map_single,
783 .unmap_single = pci_4u_unmap_single,
784 .map_sg = pci_4u_map_sg,
785 .unmap_sg = pci_4u_unmap_sg,
786 .dma_sync_single_for_cpu = pci_4u_dma_sync_single_for_cpu,
787 .dma_sync_sg_for_cpu = pci_4u_dma_sync_sg_for_cpu,
790 static void ali_sound_dma_hack(struct pci_dev *pdev, int set_bit)
792 struct pci_dev *ali_isa_bridge;
795 /* ALI sound chips generate 31-bits of DMA, a special register
796 * determines what bit 31 is emitted as.
798 ali_isa_bridge = pci_get_device(PCI_VENDOR_ID_AL,
799 PCI_DEVICE_ID_AL_M1533,
802 pci_read_config_byte(ali_isa_bridge, 0x7e, &val);
807 pci_write_config_byte(ali_isa_bridge, 0x7e, val);
808 pci_dev_put(ali_isa_bridge);
811 int pci_dma_supported(struct pci_dev *pdev, u64 device_mask)
813 struct pcidev_cookie *pcp = pdev->sysdata;
817 dma_addr_mask = 0xffffffff;
819 struct pci_iommu *iommu = pcp->pbm->iommu;
821 dma_addr_mask = iommu->dma_addr_mask;
823 if (pdev->vendor == PCI_VENDOR_ID_AL &&
824 pdev->device == PCI_DEVICE_ID_AL_M5451 &&
825 device_mask == 0x7fffffff) {
826 ali_sound_dma_hack(pdev,
827 (dma_addr_mask & 0x80000000) != 0);
832 if (device_mask >= (1UL << 32UL))
835 return (device_mask & dma_addr_mask) == dma_addr_mask;