Linux Audio

Check our new training course

Loading...
v6.2
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 4 */
 5
 6#include <linux/init.h>
 7#include <linux/mm.h>
 8#include <linux/proc_fs.h>
 9#include <linux/kernel.h>
10#include <linux/of.h>
11
12#include <asm/machdep.h>
13#include <asm/vdso_datapage.h>
14#include <asm/rtas.h>
15#include <linux/uaccess.h>
 
16
17#ifdef CONFIG_PPC64
18
19static loff_t page_map_seek(struct file *file, loff_t off, int whence)
20{
21	return fixed_size_llseek(file, off, whence, PAGE_SIZE);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22}
23
24static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
25			      loff_t *ppos)
26{
27	return simple_read_from_buffer(buf, nbytes, ppos,
28			pde_data(file_inode(file)), PAGE_SIZE);
29}
30
31static int page_map_mmap( struct file *file, struct vm_area_struct *vma )
32{
33	if ((vma->vm_end - vma->vm_start) > PAGE_SIZE)
 
 
34		return -EINVAL;
35
36	remap_pfn_range(vma, vma->vm_start,
37			__pa(pde_data(file_inode(file))) >> PAGE_SHIFT,
38			PAGE_SIZE, vma->vm_page_prot);
39	return 0;
40}
41
42static const struct proc_ops page_map_proc_ops = {
43	.proc_lseek	= page_map_seek,
44	.proc_read	= page_map_read,
45	.proc_mmap	= page_map_mmap,
46};
47
48
49static int __init proc_ppc64_init(void)
50{
51	struct proc_dir_entry *pde;
52
53	pde = proc_create_data("powerpc/systemcfg", S_IFREG | 0444, NULL,
54			       &page_map_proc_ops, vdso_data);
55	if (!pde)
56		return 1;
57	proc_set_size(pde, PAGE_SIZE);
58
59	return 0;
60}
61__initcall(proc_ppc64_init);
62
63#endif /* CONFIG_PPC64 */
64
65/*
66 * Create the ppc64 and ppc64/rtas directories early. This allows us to
67 * assume that they have been previously created in drivers.
68 */
69static int __init proc_ppc64_create(void)
70{
71	struct proc_dir_entry *root;
72
73	root = proc_mkdir("powerpc", NULL);
74	if (!root)
75		return 1;
76
77#ifdef CONFIG_PPC64
78	if (!proc_symlink("ppc64", NULL, "powerpc"))
79		pr_err("Failed to create link /proc/ppc64 -> /proc/powerpc\n");
80#endif
81
82	if (!of_find_node_by_path("/rtas"))
83		return 0;
84
85	if (!proc_mkdir("rtas", root))
86		return 1;
87
88	if (!proc_symlink("rtas", NULL, "powerpc/rtas"))
89		return 1;
90
91	return 0;
92}
93core_initcall(proc_ppc64_create);
v3.1
 
  1/*
  2 * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation
  3 *
  4 * This program is free software; you can redistribute it and/or modify
  5 * it under the terms of the GNU General Public License as published by
  6 * the Free Software Foundation; either version 2 of the License, or
  7 * (at your option) any later version.
  8 *
  9 * This program is distributed in the hope that it will be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 * GNU General Public License for more details.
 13 *
 14 * You should have received a copy of the GNU General Public License
 15 * along with this program; if not, write to the Free Software
 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 17 */
 18
 19#include <linux/init.h>
 20#include <linux/mm.h>
 21#include <linux/proc_fs.h>
 22#include <linux/kernel.h>
 
 23
 24#include <asm/machdep.h>
 25#include <asm/vdso_datapage.h>
 26#include <asm/rtas.h>
 27#include <asm/uaccess.h>
 28#include <asm/prom.h>
 29
 30#ifdef CONFIG_PPC64
 31
 32static loff_t page_map_seek( struct file *file, loff_t off, int whence)
 33{
 34	loff_t new;
 35	struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
 36
 37	switch(whence) {
 38	case 0:
 39		new = off;
 40		break;
 41	case 1:
 42		new = file->f_pos + off;
 43		break;
 44	case 2:
 45		new = dp->size + off;
 46		break;
 47	default:
 48		return -EINVAL;
 49	}
 50	if ( new < 0 || new > dp->size )
 51		return -EINVAL;
 52	return (file->f_pos = new);
 53}
 54
 55static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
 56			      loff_t *ppos)
 57{
 58	struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
 59	return simple_read_from_buffer(buf, nbytes, ppos, dp->data, dp->size);
 60}
 61
 62static int page_map_mmap( struct file *file, struct vm_area_struct *vma )
 63{
 64	struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
 65
 66	if ((vma->vm_end - vma->vm_start) > dp->size)
 67		return -EINVAL;
 68
 69	remap_pfn_range(vma, vma->vm_start, __pa(dp->data) >> PAGE_SHIFT,
 70						dp->size, vma->vm_page_prot);
 
 71	return 0;
 72}
 73
 74static const struct file_operations page_map_fops = {
 75	.llseek	= page_map_seek,
 76	.read	= page_map_read,
 77	.mmap	= page_map_mmap
 78};
 79
 80
 81static int __init proc_ppc64_init(void)
 82{
 83	struct proc_dir_entry *pde;
 84
 85	pde = proc_create_data("powerpc/systemcfg", S_IFREG|S_IRUGO, NULL,
 86			       &page_map_fops, vdso_data);
 87	if (!pde)
 88		return 1;
 89	pde->size = PAGE_SIZE;
 90
 91	return 0;
 92}
 93__initcall(proc_ppc64_init);
 94
 95#endif /* CONFIG_PPC64 */
 96
 97/*
 98 * Create the ppc64 and ppc64/rtas directories early. This allows us to
 99 * assume that they have been previously created in drivers.
100 */
101static int __init proc_ppc64_create(void)
102{
103	struct proc_dir_entry *root;
104
105	root = proc_mkdir("powerpc", NULL);
106	if (!root)
107		return 1;
108
109#ifdef CONFIG_PPC64
110	if (!proc_symlink("ppc64", NULL, "powerpc"))
111		pr_err("Failed to create link /proc/ppc64 -> /proc/powerpc\n");
112#endif
113
114	if (!of_find_node_by_path("/rtas"))
115		return 0;
116
117	if (!proc_mkdir("rtas", root))
118		return 1;
119
120	if (!proc_symlink("rtas", NULL, "powerpc/rtas"))
121		return 1;
122
123	return 0;
124}
125core_initcall(proc_ppc64_create);