Browse Source

config: add CONFIG_PAGE_SIZE and CONFIG_INIT_PAGE_SIZE

master
Aaron Lindsay 8 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 View File

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


+ 2
- 0
config_example View File

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

+ 1
- 1
drivers/pl110.c View File

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


+ 1
- 1
drivers/pl111.c View File

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


+ 0
- 2
include/frames.h View File

@ -23,8 +23,6 @@
#include <list.h>
#define MM_PAGE_SIZE 4096
struct frame {
void *address;
struct dlist_node list;


+ 12
- 12
kernel/frames.c View File

@ -60,16 +60,16 @@ static void add_physical_memory(void *start, void *end) {
//If region starts at 0x0, make it start at next page to not screw up null pointer detection, etc.
if (start == 0)
start = (char *)start + MM_PAGE_SIZE;
start = (char *)start + CONFIG_PAGE_SIZE;
//make sure both start and end address are aligned to the size of a page
if ((arch_uint_ptr)start % MM_PAGE_SIZE != 0)
start = (char*)start + (MM_PAGE_SIZE - ((arch_uint_ptr)start % MM_PAGE_SIZE));
if (((arch_uint_ptr)end + 1) % MM_PAGE_SIZE != 0)
end = (char*)end - ((arch_uint_ptr)end + 1) % MM_PAGE_SIZE;
if ((arch_uint_ptr)start % CONFIG_PAGE_SIZE != 0)
start = (char*)start + (CONFIG_PAGE_SIZE - ((arch_uint_ptr)start % CONFIG_PAGE_SIZE));
if (((arch_uint_ptr)end + 1) % CONFIG_PAGE_SIZE != 0)
end = (char*)end - ((arch_uint_ptr)end + 1) % CONFIG_PAGE_SIZE;
if ((char *)end + 1 - (char *)start < MM_PAGE_SIZE<<1) {
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);
if ((char *)end + 1 - (char *)start < CONFIG_PAGE_SIZE<<1) {
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);
return;
}
@ -78,13 +78,13 @@ static void add_physical_memory(void *start, void *end) {
//TODO we're potentially losing memory here because we're calculating
//the number of page structs we need even for those pages that will contain only page structs
num_pages = ((char *)end + 1 - (char *)start) / MM_PAGE_SIZE;
usable_pages = num_pages - num_pages * sizeof(struct frame) / MM_PAGE_SIZE;
if (num_pages * sizeof(struct frame) % MM_PAGE_SIZE)
num_pages = ((char *)end + 1 - (char *)start) / CONFIG_PAGE_SIZE;
usable_pages = num_pages - num_pages * sizeof(struct frame) / CONFIG_PAGE_SIZE;
if (num_pages * sizeof(struct frame) % CONFIG_PAGE_SIZE)
usable_pages--;
p = (struct frame *)start;
for (page = ((char *)start) + (num_pages - usable_pages)*MM_PAGE_SIZE; page < end; page = (void *)(((char *)page) + MM_PAGE_SIZE)) {
for (page = ((char *)start) + (num_pages - usable_pages)*CONFIG_PAGE_SIZE; page < end; page = (void *)(((char *)page) + CONFIG_PAGE_SIZE)) {
p->address = page;
insert_page_frame(p);
p++;
@ -115,7 +115,7 @@ struct frame* get_free_frames(unsigned int power) {
for (it2 = container(it->list.next, struct frame, list);
it2->list.next != &free_frames_list && curr_pages < num_pages;
it2 = container(it2->list.next, struct frame, list)) {
if ((char*)it2->address != (char*)container(it2->list.prev, struct frame, list)->address + MM_PAGE_SIZE) {
if ((char*)it2->address != (char*)container(it2->list.prev, struct frame, list)->address + CONFIG_PAGE_SIZE) {
it = it2; //fast-forward 'it' to start of next contiguous section of pages
break;
} else {


Loading…
Cancel
Save