diff options
| -rw-r--r-- | libdrm/radeon/radeon_bo.h | 17 | ||||
| -rw-r--r-- | libdrm/radeon/radeon_bo_gem.c | 19 | ||||
| -rw-r--r-- | libdrm/radeon/radeon_bo_gem.h | 17 | ||||
| -rw-r--r-- | libdrm/radeon/radeon_cs_gem.c | 162 | ||||
| -rw-r--r-- | libdrm/radeon/radeon_cs_gem.h | 17 | 
5 files changed, 143 insertions, 89 deletions
| diff --git a/libdrm/radeon/radeon_bo.h b/libdrm/radeon/radeon_bo.h index a0739265..f884e0fa 100644 --- a/libdrm/radeon/radeon_bo.h +++ b/libdrm/radeon/radeon_bo.h @@ -2,20 +2,21 @@   * Copyright © 2008 Jérôme Glisse   * All Rights Reserved.   *  - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the   * "Software"), to deal in the Software without restriction, including   * without limitation the rights to use, copy, modify, merge, publish,   * distribute, sub license, and/or sell copies of the Software, and to   * permit persons to whom the Software is furnished to do so, subject to   * the following conditions:   *  - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR  - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE    * USE OR OTHER DEALINGS IN THE SOFTWARE.   *   * The above copyright notice and this permission notice (including the diff --git a/libdrm/radeon/radeon_bo_gem.c b/libdrm/radeon/radeon_bo_gem.c index 04e36c59..fc198711 100644 --- a/libdrm/radeon/radeon_bo_gem.c +++ b/libdrm/radeon/radeon_bo_gem.c @@ -3,20 +3,21 @@   * Copyright © 2008 Jérôme Glisse   * All Rights Reserved.   *  - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the   * "Software"), to deal in the Software without restriction, including   * without limitation the rights to use, copy, modify, merge, publish,   * distribute, sub license, and/or sell copies of the Software, and to   * permit persons to whom the Software is furnished to do so, subject to   * the following conditions:   *  - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR  - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE    * USE OR OTHER DEALINGS IN THE SOFTWARE.   *   * The above copyright notice and this permission notice (including the @@ -102,6 +103,7 @@ static struct radeon_bo *bo_open(struct radeon_bo_manager *bom,              return NULL;          }      } +    radeon_bo_ref(bo);      return (struct radeon_bo*)bo;  } @@ -118,7 +120,6 @@ static void bo_unref(struct radeon_bo *bo)          return;      }      if (bo->cref) { -        /* FIXME: what to do ? */          return;      }      if (bo_gem->map_count) { diff --git a/libdrm/radeon/radeon_bo_gem.h b/libdrm/radeon/radeon_bo_gem.h index d0997614..aaefd8c3 100644 --- a/libdrm/radeon/radeon_bo_gem.h +++ b/libdrm/radeon/radeon_bo_gem.h @@ -3,20 +3,21 @@   * Copyright © 2008 Jérôme Glisse   * All Rights Reserved.   *  - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the   * "Software"), to deal in the Software without restriction, including   * without limitation the rights to use, copy, modify, merge, publish,   * distribute, sub license, and/or sell copies of the Software, and to   * permit persons to whom the Software is furnished to do so, subject to   * the following conditions:   *  - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR  - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE    * USE OR OTHER DEALINGS IN THE SOFTWARE.   *   * The above copyright notice and this permission notice (including the diff --git a/libdrm/radeon/radeon_cs_gem.c b/libdrm/radeon/radeon_cs_gem.c index 7ed5780b..00aa9086 100644 --- a/libdrm/radeon/radeon_cs_gem.c +++ b/libdrm/radeon/radeon_cs_gem.c @@ -2,20 +2,21 @@   * Copyright © 2008 Jérôme Glisse   * All Rights Reserved.   *  - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the   * "Software"), to deal in the Software without restriction, including   * without limitation the rights to use, copy, modify, merge, publish,   * distribute, sub license, and/or sell copies of the Software, and to   * permit persons to whom the Software is furnished to do so, subject to   * the following conditions:   *  - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR  - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE    * USE OR OTHER DEALINGS IN THE SOFTWARE.   *   * The above copyright notice and this permission notice (including the @@ -24,22 +25,27 @@   */  /*   * Authors: + *      Aapo Tahkola <aet@rasterburn.org> + *      Nicolai Haehnle <prefect_@gmx.net>   *      Jérôme Glisse <glisse@freedesktop.org>   */  #include <errno.h>  #include <stdlib.h> +#include <sys/mman.h> +#include <sys/ioctl.h>  #include "radeon_cs.h"  #include "radeon_cs_gem.h"  #include "radeon_bo_gem.h"  #include "drm.h" +#include "xf86drm.h"  #include "radeon_drm.h"  #pragma pack(1)  struct cs_reloc_gem {      uint32_t    handle; -    uint32_t    domains; -    uint32_t    soffset; -    uint32_t    eoffset; +    uint32_t    rdomain; +    uint32_t    wdomain; +    uint32_t    cnt;  };  #pragma pack() @@ -49,6 +55,7 @@ struct cs_gem {      struct drm_radeon_cs_chunk  chunks[2];      unsigned                    nrelocs;      uint32_t                    *relocs; +    struct radeon_bo            **relocs_bo;  };  static struct radeon_cs *cs_create(struct radeon_cs_manager *csm, @@ -74,8 +81,16 @@ static struct radeon_cs *cs_create(struct radeon_cs_manager *csm,      csg->base.relocs_total_size = 0;      csg->base.crelocs = 0;      csg->nrelocs = 4096 / (4 * 4) ; +    csg->relocs_bo = (struct radeon_bo**)calloc(1, +                                                csg->nrelocs*sizeof(void*)); +    if (csg->relocs_bo == NULL) { +        free(csg->base.packets); +        free(csg); +        return NULL; +    }      csg->base.relocs = csg->relocs = (uint32_t*)calloc(1, 4096);      if (csg->relocs == NULL) { +        free(csg->relocs_bo);          free(csg->base.packets);          free(csg);          return NULL; @@ -91,6 +106,7 @@ static struct radeon_cs *cs_create(struct radeon_cs_manager *csm,  static int cs_write_dword(struct radeon_cs *cs, uint32_t dword)  { +    struct cs_gem *csg = (struct cs_gem*)cs;      if (cs->cdw >= cs->ndw) {          uint32_t tmp, *ptr;          tmp = (cs->cdw + 1 + 0x3FF) & (~0x3FF); @@ -100,11 +116,10 @@ static int cs_write_dword(struct radeon_cs *cs, uint32_t dword)          }          cs->packets = ptr;          cs->ndw = tmp; +        csg->chunks[0].chunk_data = (uint64_t)(intptr_t)csg->base.packets;      }      cs->packets[cs->cdw++] = dword; -    if (cs->section) { -        cs->section_cdw++; -    } +    csg->chunks[0].length_dw += 1;      return 0;  } @@ -116,6 +131,7 @@ static int cs_write_reloc(struct radeon_cs *cs,  {      struct cs_gem *csg = (struct cs_gem*)cs;      struct cs_reloc_gem *reloc; +    uint32_t idx;      unsigned i;      /* check reloc window */ @@ -127,38 +143,73 @@ static int cs_write_reloc(struct radeon_cs *cs,      }      /* check if bo is already referenced */      for(i = 0; i < cs->crelocs; i++) { -        reloc = (struct cs_reloc_gem*)&csg->relocs[i * 4]; +        idx = i * 4; +        reloc = (struct cs_reloc_gem*)&csg->relocs[idx];          if (reloc->handle == bo->handle) {              /* update start offset and size */ -            if (eoffset > reloc->eoffset) { -                reloc->eoffset = eoffset; +            switch (bo->domains) { +            case RADEON_GEM_DOMAIN_VRAM: +                reloc->rdomain = 0; +                reloc->wdomain = RADEON_GEM_DOMAIN_VRAM; +                break; +            case RADEON_GEM_DOMAIN_GTT: +                reloc->rdomain = RADEON_GEM_DOMAIN_GTT; +                reloc->wdomain = 0; +                break; +            default: +                exit(0); +                break;              } -            if (soffset < reloc->soffset) { -                reloc->soffset = soffset; -            } -            reloc->domains |= domains; +            reloc->cnt++; +            cs_write_dword(cs, 0xc0001000); +            cs_write_dword(cs, idx);              return 0;          }      }      /* add bo */      if (csg->base.crelocs >= csg->nrelocs) {          uint32_t *tmp, size; -        size = (csg->nrelocs * 4 * 4) + (4096 / (4 * 4)); +        size = ((csg->nrelocs + 1) * sizeof(struct radeon_bo*)); +        tmp = (uint32_t*)realloc(csg->relocs_bo, size); +        if (tmp == NULL) { +            return -ENOMEM; +        } +        csg->relocs_bo = (struct radeon_bo**)tmp; +        size = ((csg->nrelocs + 1) * 4 * 4);          tmp = (uint32_t*)realloc(csg->relocs, size);          if (tmp == NULL) {              return -ENOMEM;          }          cs->relocs = csg->relocs = tmp; -        csg->nrelocs = size / (4 * 4); +        csg->nrelocs += 1; +        csg->chunks[1].chunk_data = (uint64_t)(intptr_t)csg->relocs;      } -    reloc = (struct cs_reloc_gem*)&csg->relocs[csg->base.crelocs * 4]; +    csg->relocs_bo[csg->base.crelocs] = bo; +    idx = (csg->base.crelocs++) * 4; +    reloc = (struct cs_reloc_gem*)&csg->relocs[idx];      reloc->handle = bo->handle; -    reloc->soffset = soffset; -    reloc->eoffset = eoffset; -    reloc->domains = domains; -    cs->crelocs++; +    reloc->rdomain = bo->domains; +    reloc->wdomain = bo->domains; +    switch (bo->domains) { +    case RADEON_GEM_DOMAIN_VRAM: +        reloc->rdomain = 0; +        reloc->wdomain = RADEON_GEM_DOMAIN_VRAM; +        break; +    case RADEON_GEM_DOMAIN_GTT: +        reloc->rdomain = RADEON_GEM_DOMAIN_GTT; +        reloc->wdomain = 0; +        break; +    default: +        exit(0); +        break; +    } +    reloc->cnt = 1; +    csg->chunks[1].length_dw += 4;      radeon_bo_ref(bo); +    cs->relocs_total_size += bo->size; +    cs_write_dword(cs, 0xc0001000); +    cs_write_dword(cs, idx);      return 0;  } @@ -168,19 +219,6 @@ static int cs_begin(struct radeon_cs *cs,                      const char *func,                      int line)  { -    if (cs->section) { -        fprintf(stderr, "CS already in a section(%s,%s,%d)\n", -                cs->section_file, cs->section_func, cs->section_line); -        fprintf(stderr, "CS can't start section(%s,%s,%d)\n", -                file, func, line); -        return -EPIPE; -    } -    cs->section = 1; -    cs->section_ndw = ndw; -    cs->section_cdw = 0; -    cs->section_file = file; -    cs->section_func = func; -    cs->section_line = line;      return 0;  } @@ -190,29 +228,38 @@ static int cs_end(struct radeon_cs *cs,                    int line)  { -    if (!cs->section) { -        fprintf(stderr, "CS no section to end at (%s,%s,%d)\n", -                file, func, line); -        return -EPIPE; -    }      cs->section = 0; -    if (cs->section_ndw != cs->section_cdw) { -        fprintf(stderr, "CS section size missmatch start at (%s,%s,%d)\n", -                cs->section_file, cs->section_func, cs->section_line); -        fprintf(stderr, "CS section end at (%s,%s,%d)\n", -                file, func, line); -        return -EPIPE; -    }      return 0;  }  static int cs_emit(struct radeon_cs *cs)  { +    struct cs_gem *csg = (struct cs_gem*)cs; +    uint64_t chunk_array[2]; +    int r; + +    chunk_array[0] = (uint64_t)(intptr_t)&csg->chunks[0]; +    chunk_array[1] = (uint64_t)(intptr_t)&csg->chunks[1]; + +    csg->cs.num_chunks = 2; +    csg->cs.chunks = (uint64_t)(intptr_t)chunk_array; + +    r = drmCommandWriteRead(cs->csm->fd, DRM_RADEON_CS2, +                            &csg->cs, sizeof(struct drm_radeon_cs2)); +    if (r) { +        return r; +    } +    for(i = 0; i < cs->crelocs; i++) { +        radeon_bo_unref(csg->relocs_bo[i]);     +    }      return 0;  }  static int cs_destroy(struct radeon_cs *cs)  { +    struct cs_gem *csg = (struct cs_gem*)cs; + +    free(csg->relocs_bo);      free(cs->relocs);      free(cs->packets);      free(cs); @@ -221,17 +268,20 @@ static int cs_destroy(struct radeon_cs *cs)  static int cs_erase(struct radeon_cs *cs)  { +    struct cs_gem *csg = (struct cs_gem*)cs; +      cs->relocs_total_size = 0; -    cs->relocs = NULL; -    cs->crelocs = 0;      cs->cdw = 0;      cs->section = 0; +    cs->crelocs = 0; +    csg->chunks[0].length_dw = 0; +    csg->chunks[1].length_dw = 0;      return 0;  }  static int cs_need_flush(struct radeon_cs *cs)  { -    return (cs->relocs_total_size > (7*1024*1024)); +    return (cs->relocs_total_size > (16*1024*1024));  }  struct radeon_cs_funcs  radeon_cs_funcs = { diff --git a/libdrm/radeon/radeon_cs_gem.h b/libdrm/radeon/radeon_cs_gem.h index a032a8cc..f50c5e84 100644 --- a/libdrm/radeon/radeon_cs_gem.h +++ b/libdrm/radeon/radeon_cs_gem.h @@ -3,20 +3,21 @@   * Copyright © 2008 Jérôme Glisse   * All Rights Reserved.   *  - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the   * "Software"), to deal in the Software without restriction, including   * without limitation the rights to use, copy, modify, merge, publish,   * distribute, sub license, and/or sell copies of the Software, and to   * permit persons to whom the Software is furnished to do so, subject to   * the following conditions:   *  - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR  - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE    * USE OR OTHER DEALINGS IN THE SOFTWARE.   *   * The above copyright notice and this permission notice (including the | 
