1 // SPDX-License-Identifier: (GPL-2.0-only OR B 1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) 2 // 2 // 3 // This file is provided under a dual BSD/GPLv 3 // This file is provided under a dual BSD/GPLv2 license. When using or 4 // redistributing this file, you may do so und 4 // redistributing this file, you may do so under either license. 5 // 5 // 6 // Copyright(c) 2018-2022 Intel Corporation !! 6 // Copyright(c) 2018-2022 Intel Corporation. All rights reserved. 7 // 7 // 8 // Author: Keyon Jie <yang.jie@linux.intel.com 8 // Author: Keyon Jie <yang.jie@linux.intel.com> 9 // 9 // 10 10 11 #include <linux/unaligned.h> !! 11 #include <asm/unaligned.h> 12 #include <linux/io-64-nonatomic-lo-hi.h> 12 #include <linux/io-64-nonatomic-lo-hi.h> 13 #include <linux/device.h> 13 #include <linux/device.h> 14 #include <sound/memalloc.h> 14 #include <sound/memalloc.h> 15 #include <linux/module.h> 15 #include <linux/module.h> 16 #include "sof-utils.h" 16 #include "sof-utils.h" 17 17 18 /* 18 /* 19 * Generic buffer page table creation. 19 * Generic buffer page table creation. 20 * Take the each physical page address and dro 20 * Take the each physical page address and drop the least significant unused 21 * bits from each (based on PAGE_SIZE). Then p 21 * bits from each (based on PAGE_SIZE). Then pack valid page address bits 22 * into compressed page table. 22 * into compressed page table. 23 */ 23 */ 24 24 25 int snd_sof_create_page_table(struct device *d 25 int snd_sof_create_page_table(struct device *dev, 26 struct snd_dma_b 26 struct snd_dma_buffer *dmab, 27 unsigned char *p 27 unsigned char *page_table, size_t size) 28 { 28 { 29 int i, pages; 29 int i, pages; 30 30 31 pages = snd_sgbuf_aligned_pages(size); 31 pages = snd_sgbuf_aligned_pages(size); 32 32 33 dev_dbg(dev, "generating page table fo 33 dev_dbg(dev, "generating page table for %p size 0x%zx pages %d\n", 34 dmab->area, size, pages); 34 dmab->area, size, pages); 35 35 36 for (i = 0; i < pages; i++) { 36 for (i = 0; i < pages; i++) { 37 /* 37 /* 38 * The number of valid address 38 * The number of valid address bits for each page is 20. 39 * idx determines the byte pos 39 * idx determines the byte position within page_table 40 * where the current page's ad 40 * where the current page's address is stored 41 * in the compressed page_tabl 41 * in the compressed page_table. 42 * This can be calculated by m 42 * This can be calculated by multiplying the page number by 2.5. 43 */ 43 */ 44 u32 idx = (5 * i) >> 1; 44 u32 idx = (5 * i) >> 1; 45 u32 pfn = snd_sgbuf_get_addr(d 45 u32 pfn = snd_sgbuf_get_addr(dmab, i * PAGE_SIZE) >> PAGE_SHIFT; 46 u8 *pg_table; 46 u8 *pg_table; 47 47 >> 48 dev_vdbg(dev, "pfn i %i idx %d pfn %x\n", i, idx, pfn); >> 49 48 pg_table = (u8 *)(page_table + 50 pg_table = (u8 *)(page_table + idx); 49 51 50 /* 52 /* 51 * pagetable compression: 53 * pagetable compression: 52 * byte 0 byte 1 byte 54 * byte 0 byte 1 byte 2 byte 3 byte 4 byte 5 53 * ___________pfn 0__________ 55 * ___________pfn 0__________ __________pfn 1___________ _pfn 2... 54 * .... .... .... .... .... 56 * .... .... .... .... .... .... .... .... .... .... .... 55 * It is created by: 57 * It is created by: 56 * 1. set current location to 58 * 1. set current location to 0, PFN index i to 0 57 * 2. put pfn[i] at current lo 59 * 2. put pfn[i] at current location in Little Endian byte order 58 * 3. calculate an intermediat 60 * 3. calculate an intermediate value as 59 * x = (pfn[i+1] << 4) | (p 61 * x = (pfn[i+1] << 4) | (pfn[i] & 0xf) 60 * 4. put x at offset (current 62 * 4. put x at offset (current location + 2) in LE byte order 61 * 5. increment current locati 63 * 5. increment current location by 5 bytes, increment i by 2 62 * 6. continue to (2) 64 * 6. continue to (2) 63 */ 65 */ 64 if (i & 1) 66 if (i & 1) 65 put_unaligned_le32((pg 67 put_unaligned_le32((pg_table[0] & 0xf) | pfn << 4, 66 pg_ 68 pg_table); 67 else 69 else 68 put_unaligned_le32(pfn 70 put_unaligned_le32(pfn, pg_table); 69 } 71 } 70 72 71 return pages; 73 return pages; 72 } 74 } 73 EXPORT_SYMBOL(snd_sof_create_page_table); 75 EXPORT_SYMBOL(snd_sof_create_page_table); 74 76 75 MODULE_LICENSE("Dual BSD/GPL"); 77 MODULE_LICENSE("Dual BSD/GPL"); 76 MODULE_DESCRIPTION("SOF utils"); << 77 78
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.