Browse Source

config: add CONFIG_PAGE_SIZE and CONFIG_INIT_PAGE_SIZE

Aaron Lindsay 6 years ago
parent
commit
1c75a68815
6 changed files with 17 additions and 16 deletions
  1. 1 0
      Makefile
  2. 2 0
      config_example
  3. 1 1
      drivers/pl110.c
  4. 1 1
      drivers/pl111.c
  5. 0 2
      include/frames.h
  6. 12 12
      kernel/frames.c

+ 1 - 0
Makefile

@@ -78,6 +78,7 @@ config.h: config
78 78
 	@sed -i 's/#.*$$//g' config.h
79 79
 	@sed -i '/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*[nN]/d' config.h
80 80
 	@sed -i 's/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*[yY]/#define \1/g' config.h
81
+	@sed -i 's/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*\([0-9]\+\)/#define \1 \2/g' config.h
81 82
 
82 83
 clean:
83 84
 	@echo '  CLEAN   config.h'

+ 2 - 0
config_example

@@ -1,3 +1,5 @@
1 1
 CONFIG_RPI = y
2 2
 #CONFIG_VEXPRESS_A9 = y
3 3
 #CONFIG_INTEGRATOR_CP = n
4
+CONFIG_PAGE_SIZE = 0x1000
5
+CONFIG_INIT_PAGE_SIZE = 0x100000

+ 1 - 1
drivers/pl110.c

@@ -55,7 +55,7 @@ int pl110_init(struct fb *f, unsigned int color_depth) {
55 55
 
56 56
 	/* Allocate memory for framebuffer */
57 57
 	fb_size = width * height * (color_depth / 8);
58
-	power = log(fb_size) - log(MM_PAGE_SIZE);
58
+	power = log(fb_size) - log(CONFIG_PAGE_SIZE);
59 59
 	if ((unsigned int)1<<power < fb_size)
60 60
 		power++;
61 61
 	fr = get_free_frames(power);

+ 1 - 1
drivers/pl111.c

@@ -57,7 +57,7 @@ int pl111_init_dev(struct fb *f, unsigned int color_depth) {
57 57
 
58 58
 	/* Allocate memory for framebuffer */
59 59
 	fb_size = width * height * (color_depth / 8);
60
-	power = log(fb_size) - log(MM_PAGE_SIZE);
60
+	power = log(fb_size) - log(CONFIG_PAGE_SIZE);
61 61
 	if ((unsigned int)1<<power < fb_size)
62 62
 		power++;
63 63
 	fr = get_free_frames(power);

+ 0 - 2
include/frames.h

@@ -23,8 +23,6 @@
23 23
 
24 24
 #include <list.h>
25 25
 
26
-#define MM_PAGE_SIZE 4096
27
-
28 26
 struct frame {
29 27
 	void *address;
30 28
 	struct dlist_node list;

+ 12 - 12
kernel/frames.c

@@ -60,16 +60,16 @@ static void add_physical_memory(void *start, void *end) {
60 60
 
61 61
 	//If region starts at 0x0, make it start at next page to not screw up null pointer detection, etc.
62 62
 	if (start == 0)
63
-		start = (char *)start + MM_PAGE_SIZE;
63
+		start = (char *)start + CONFIG_PAGE_SIZE;
64 64
 
65 65
 	//make sure both start and end address are aligned to the size of a page
66
-	if ((arch_uint_ptr)start % MM_PAGE_SIZE != 0)
67
-		start = (char*)start + (MM_PAGE_SIZE - ((arch_uint_ptr)start % MM_PAGE_SIZE));
68
-	if (((arch_uint_ptr)end + 1) % MM_PAGE_SIZE != 0)
69
-		end = (char*)end - ((arch_uint_ptr)end + 1) % MM_PAGE_SIZE;
66
+	if ((arch_uint_ptr)start % CONFIG_PAGE_SIZE != 0)
67
+		start = (char*)start + (CONFIG_PAGE_SIZE - ((arch_uint_ptr)start % CONFIG_PAGE_SIZE));
68
+	if (((arch_uint_ptr)end + 1) % CONFIG_PAGE_SIZE != 0)
69
+		end = (char*)end - ((arch_uint_ptr)end + 1) % CONFIG_PAGE_SIZE;
70 70
 
71
-	if ((char *)end + 1 - (char *)start < MM_PAGE_SIZE<<1) {
72
-		print("Error: Supplied memory area(%x,%x) is smaller than the page size (%d)\n", (arch_uint_ptr)start, (arch_uint_ptr)end, MM_PAGE_SIZE);
71
+	if ((char *)end + 1 - (char *)start < CONFIG_PAGE_SIZE<<1) {
72
+		print("Error: Supplied memory area(%x,%x) is smaller than the page size (%d)\n", (arch_uint_ptr)start, (arch_uint_ptr)end, CONFIG_PAGE_SIZE);
73 73
 		return;
74 74
 	}
75 75
 
@@ -78,13 +78,13 @@ static void add_physical_memory(void *start, void *end) {
78 78
 
79 79
 	//TODO we're potentially losing memory here because we're calculating
80 80
 	//the number of page structs we need even for those pages that will contain only page structs
81
-	num_pages = ((char *)end + 1 - (char *)start) / MM_PAGE_SIZE;
82
-	usable_pages = num_pages - num_pages * sizeof(struct frame) / MM_PAGE_SIZE;
83
-	if (num_pages * sizeof(struct frame) % MM_PAGE_SIZE)
81
+	num_pages = ((char *)end + 1 - (char *)start) / CONFIG_PAGE_SIZE;
82
+	usable_pages = num_pages - num_pages * sizeof(struct frame) / CONFIG_PAGE_SIZE;
83
+	if (num_pages * sizeof(struct frame) % CONFIG_PAGE_SIZE)
84 84
 		usable_pages--;
85 85
 
86 86
 	p = (struct frame *)start;
87
-	for (page = ((char *)start) + (num_pages - usable_pages)*MM_PAGE_SIZE; page < end; page = (void *)(((char *)page) + MM_PAGE_SIZE)) {
87
+	for (page = ((char *)start) + (num_pages - usable_pages)*CONFIG_PAGE_SIZE; page < end; page = (void *)(((char *)page) + CONFIG_PAGE_SIZE)) {
88 88
 		p->address = page;
89 89
 		insert_page_frame(p);
90 90
 		p++;
@@ -115,7 +115,7 @@ struct frame* get_free_frames(unsigned int power) {
115 115
 		for (it2 = container(it->list.next, struct frame, list);
116 116
 					it2->list.next != &free_frames_list && curr_pages < num_pages;
117 117
 					it2 = container(it2->list.next, struct frame, list)) {
118
-			if ((char*)it2->address != (char*)container(it2->list.prev, struct frame, list)->address + MM_PAGE_SIZE) {
118
+			if ((char*)it2->address != (char*)container(it2->list.prev, struct frame, list)->address + CONFIG_PAGE_SIZE) {
119 119
 				it = it2; //fast-forward 'it' to start of next contiguous section of pages
120 120
 				break;
121 121
 			} else {