Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* nommu.c: mmu-less memory info files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/mman.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/mmzone.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/hugetlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <asm/tlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <asm/div64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * display a single region to a sequenced file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static int nommu_region_show(struct seq_file *m, struct vm_region *region)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	unsigned long ino = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	dev_t dev = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	flags = region->vm_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	file = region->vm_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		struct inode *inode = file_inode(region->vm_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		dev = inode->i_sb->s_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		ino = inode->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	seq_printf(m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		   "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		   region->vm_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		   region->vm_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		   flags & VM_READ ? 'r' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		   flags & VM_WRITE ? 'w' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		   flags & VM_EXEC ? 'x' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		   flags & VM_MAYSHARE ? flags & VM_SHARED ? 'S' : 's' : 'p',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		   ((loff_t)region->vm_pgoff) << PAGE_SHIFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		   MAJOR(dev), MINOR(dev), ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		seq_pad(m, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		seq_file_path(m, file, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * display a list of all the REGIONs the kernel knows about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * - nommu kernels have a single flat list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static int nommu_region_list_show(struct seq_file *m, void *_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct rb_node *p = _p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return nommu_region_show(m, rb_entry(p, struct vm_region, vm_rb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static void *nommu_region_list_start(struct seq_file *m, loff_t *_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct rb_node *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	loff_t pos = *_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	down_read(&nommu_region_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	for (p = rb_first(&nommu_region_tree); p; p = rb_next(p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		if (pos-- == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static void nommu_region_list_stop(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	up_read(&nommu_region_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static void *nommu_region_list_next(struct seq_file *m, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	(*pos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return rb_next((struct rb_node *) v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static const struct seq_operations proc_nommu_region_list_seqop = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	.start	= nommu_region_list_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	.next	= nommu_region_list_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	.stop	= nommu_region_list_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	.show	= nommu_region_list_show
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int __init proc_nommu_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	proc_create_seq("maps", S_IRUGO, NULL, &proc_nommu_region_list_seqop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) fs_initcall(proc_nommu_init);