From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jerome Glisse Subject: Re: TTM questions Date: Thu, 15 Jul 2010 13:22:53 -0400 Message-ID: <4C3F43ED.30507@freedesktop.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: Received: from protox.org (unknown [95.130.11.66]) by gabe.freedesktop.org (Postfix) with ESMTP id 904399E75D for ; Thu, 15 Jul 2010 10:22:56 -0700 (PDT) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org Errors-To: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org To: James Simmons Cc: DRI development list List-Id: dri-devel@lists.freedesktop.org On 07/15/2010 11:54 AM, James Simmons wrote: > > Now that I'm adding in TTM support to my 3Dfx driver I have a questions. > First I noticed in almost every driver for ttm initialization that two > struct ttm_global_reference global_ref are allocated. One for TTM_GLOBAL_TTM_MEM > and one for TTM_GLOBAL_TTM_BO. For a graphics card with only VRAM fb memory do > you need to allocate the TTM_GLOBAL_TTM_BO area? From what I can tell that is yes. > After you set that up do pretty much do a: > Yes you need to have the global stuff this are accounting stuff. > ret = ttm_bo_device_init(&bdev, bo_global_ref.ref.object, > &my_bo_driver, DRM_FILE_PAGE_OFFSET, > dma_flag); > if (ret) { > DRM_ERROR("failed!!!\n"); > return ret; > } > > ret = ttm_bo_init_mm(bdev, TTM_PL_VRAM, vram_size>> PAGE_SHIFT); > if (ret) { > DRM_ERROR(dev, "failed\n"); > return ret; > } > > // vram start > placement.fpfn = 0; > // static fb pci region length > placement.lpfn = pci_resource_len(pdev, num); // static fb pci region > // Anything else needed in placement? > fpfn & lfpn are page frame number ie if you want to have your buffer allocated between address 0x10000000 & 0x20000000 you set : placement.fpfn = 0x10000000 / 4096; placement.lpfn = 0x20000000 / 4096; > // What is the alignment for non-tile framebuffers? > // Is this related to info->pixmap.buf_align > page_align = PAGE_MASK; > Alignement is to force your buffer to be aligned on some address. For instance some hw need that the 8 lower bits of the framebuffer address to be zero to have this set: page_align = 256; //(2^8) > // Usually the driver wants to start at the very beginning of vram > buffer_start = 0; > ttm_buffer_object *bo = kmalloc(sizeof(*bo); > > ret = ttm_bo_init(&bdev,&bo, vram_size, TTM_PL_VRAM, > &placement, align, buffer_start, false, NULL, > vram_size, my_bo_del_ttm); > if (ret) { > // ttm will call my_bo_del_ttm if it fails.. > return ret; > } > > // Is the below needed ? > ret = ttm_bo_reserve(bo, false, false, false, 0); > if (ret) > return ret; > > ret = ttm_bo_validate(bo,&nvbo->placement, false, false, false); > > ttm_bo_unreserve(bo); > > > Please fill in what I'm missing. > bo_reserve/unreserve is for reserving a bo as multiple context might access same bo. By reserving/unreserving you assure you are the only one accessing the bo. ttm_bo_validate is used when you want the gpu to do some work with the bo. You need the memory manager to place the bo into visible gpu ram and that's what ttm_bo_validate do. Once a bo is no more needed ttm might move it out of vram in your back. Hope it helps. Cheers, Jerome