linux kernel memory allocation.

Investigation into how Linux on the PS3 might lead to homebrew development.

Moderators: cheriff, emoon

Post Reply
IronPeter
Posts: 207
Joined: Mon Aug 06, 2007 12:46 am
Contact:

linux kernel memory allocation.

Post by IronPeter »

That code allocates memory on PS3:

Code: Select all

**
 * ps3_mm_region_create - create a memory region in the vas
 * @r: pointer to a struct mem_region to accept initialized values
 * @size: requested region size
 *
 * This implementation creates the region with the vas large page size.
 * @size is rounded down to a multiple of the vas large page size.
 */

static int ps3_mm_region_create(struct mem_region *r, unsigned long size)
{
        int result;
        unsigned long muid;

        r->size = _ALIGN_DOWN&#40;size, 1 << PAGE_SHIFT_16M&#41;;

        DBG&#40;"%s&#58;%d requested  %lxh\n", __func__, __LINE__, size&#41;;
        DBG&#40;"%s&#58;%d actual     %lxh\n", __func__, __LINE__, r->size&#41;;
        DBG&#40;"%s&#58;%d difference %lxh &#40;%luMB&#41;\n", __func__, __LINE__,
                &#40;unsigned long&#41;&#40;size - r->size&#41;,
                &#40;size - r->size&#41; / 1024 / 1024&#41;;

        if &#40;r->size == 0&#41; &#123;
                DBG&#40;"%s&#58;%d&#58; size == 0\n", __func__, __LINE__&#41;;
                result = -1;
                goto zero_region;
        &#125;

        result = lv1_allocate_memory&#40;r->size, PAGE_SHIFT_16M, 0,
                ALLOCATE_MEMORY_TRY_ALT_UNIT, &r->base, &muid&#41;;

....

On my FW ( 1.9 ) that code works after main allocation:

result = lv1_allocate_memory( 6 * 1024 * 1024, 20,0,ALLOCATE_MEMORY_TRY_ALT_UNIT, &lpar, &muid);

ioremap ( and gpu_ioremap ) works for this lpar address.

So there are 6 free MiBs of memory, unused by Linux. Why?
ps2devman
Posts: 259
Joined: Mon Oct 09, 2006 3:56 pm

Post by ps2devman »

Maybe a safety gap?
Allows future firmware update to have otheros bootstrap consumes a bit more? (for black listing or such...)
IronPeter
Posts: 207
Joined: Mon Aug 06, 2007 12:46 am
Contact:

Post by IronPeter »

Anyhow, it is interesting to test this code ( giving 6+ free MiBs to Linux ):

Code: Select all

#define PAGE_SHIFT_1M 20

r->size = _ALIGN_DOWN&#40;size, 1 << PAGE_SHIFT_1M&#41;; 
result = lv1_allocate_memory&#40;r->size, PAGE_SHIFT_1M, 0, ALLOCATE_MEMORY_TRY_ALT_UNIT, &r->base, &muid&#41;; 

Otherwise it is possible to write driver for additional memory allocation.
androvsky
Posts: 33
Joined: Sun Nov 11, 2007 5:59 am

Post by androvsky »

IronPeter, this is probably off-topic, but I've been wondering if the PS3 you're testing on has some PS2 hardware in it. It might be interesting if you stumbled across that... ;)
IronPeter
Posts: 207
Joined: Mon Aug 06, 2007 12:46 am
Contact:

Post by IronPeter »

I have no ideas about PS2 inside my PS3. Really no ideas :).
IronPeter
Posts: 207
Joined: Mon Aug 06, 2007 12:46 am
Contact:

alloc_memory - gpu_ioremap - release_memory cheat

Post by IronPeter »

I used memory chunk allocated by lv1_allocate_memory( 1 << 20, 20, 0, 0x04, &xdr_lpar, &muid );

The function lv1_gpu_context_iomap( context.handle, 0, xdr_lpar, 1 << 20, 0 ) returns 0. But RSX failed to write/read that memory. Why?

lv1_gpu_context_iomap( context.handle, 0, xdr_frame_buffer, 1 << 20, 0 ) works well for xdr frame buffer, it can be made visible both at GPU_IOIF and 0 addresses.

PS. I tried to test

1.) lv1_allocate_memory

2.) lv1_gpu_context_iomap

3.) lv1_release_memory

4.) some DMA transfers by GPU

I wanted to check GPU DMA protection (any access by CPU to released memory causes bus error ). But I failed at 2.)
Post Reply