/* * Copyright 2010 Jerome Glisse * * 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 * on 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 above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * 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 AUTHOR(S) AND/OR THEIR 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. * * Authors: * Jerome Glisse */ #include #include #include #include "bof.h" /* * helpers */ static int bof_entry_grow(bof_t *bof) { bof_t **array; if (bof->array_size < bof->nentry) return 0; array = realloc(bof->array, (bof->nentry + 16) * sizeof(void*)); if (array == NULL) return -ENOMEM; bof->array = array; bof->nentry += 16; return 0; } /* * object */ bof_t *bof_object(void) { bof_t *object; object = calloc(1, sizeof(bof_t)); if (object == NULL) return NULL; object->refcount = 1; object->type = BOF_TYPE_OBJECT; object->size = 12; return object; } bof_t *bof_object_get(bof_t *object, const char *keyname) { unsigned i; for (i = 0; i < object->array_size; i += 2) { if (!strcmp(object->array[i]->value, keyname)) { return object->array[i + 1]; } } return NULL; } int bof_object_set(bof_t *object, const char *keyname, bof_t *value) { bof_t *key; int r; if (object->type != BOF_TYPE_OBJECT) return -EINVAL; r = bof_entry_grow(object); if (r) return r; key = bof_string(keyname); if (key == NULL) return -ENOMEM; object->array[object->array_size++] = key; object->array[object->array_size++] = value; object->size += value->size; object->size += key->size; bof_incref(value); return 0; } /* * array */ bof_t *bof_array(void) { bof_t *array = bof_object(); if (array == NULL) return NULL; array->type = BOF_TYPE_ARRAY; array->size = 12; return array; } int bof_array_append(bof_t *array, bof_t *value) { int r; if (array->type != BOF_TYPE_ARRAY) return -EINVAL; r = bof_entry_grow(array); if (r) return r; array->array[array->array_size++] = value; array->size += value->size; bof_incref(value); return 0; } bof_t *bof_array_get(bof_t *bof, unsigned i) { if (!bof_is_array(bof) || i >= bof->array_size) return NULL; return bof->array[i]; } unsigned bof_array_size(bof_t *bof) { if (!bof_is_array(bof)) return 0; return bof->array_size; } /* * blob */ bof_t *bof_blob(unsigned size, void *value) { bof_t *blob = bof_object(); if (blob == NULL) return NULL; blob->type = BOF_TYPE_BLOB; blob->value = calloc(1, size); if (blob->value == NULL) { bof_decref(blob); return NULL; } blob->size = size; memcpy(blob->value, value, size); blob->size += 12; return blob; } unsigned bof_blob_size(bof_t *bof) { if (!bof_is_blob(bof)) return 0; return bof->size - 12; } void *bof_blob_value(bof_t *bof) { if (!bof_is_blob(bof)) return NULL; return bof->value; } /* * string */ bof_t *bof_string(const char *value) { bof_t *string = bof_object(); if (string == NULL) return NULL; string->type = BOF_TYPE_STRING; string->size = strlen(value) + 1; string->value = calloc(1, string->size); if (string->value == NULL) { bof_decref(string); return NULL; } strcpy(string->value, value); string->size += 12; return string; } /* * int32 */ bof_t *bof_int32(int32_t value) { bof_t *int32 = bof_object(); if (int32 == NULL) return NULL; int32->type = BOF_TYPE_INT32; int32->size = 4; int32->value = calloc(1, int32->size); if (int32->value == NULL) { bof_decref(int32); return NULL; } memcpy(int32->value, &value, 4); int32->size += 12; return int32; } int32_t bof_int32_value(bof_t *bof) { return *((uint32_t*)bof->value); } /* * common */ static voi/* * Copyright (C) 2008 Maarten Maathuis. * All Rights Reserved. * * 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, sublicense, 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 above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial * portions of the Software. * * 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 NONINFRINGEMENT. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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. * */ #ifndef __NV50_I2C_H__ #define __NV50_I2C_H__ #include <linux/i2c.h> #include <linux/i2c-id.h> #include <linux/i2c-algo-bit.h> #include "drmP.h" #include "drm.h" #include "nv50_display.h" struct nv50_i2c_channel { struct drm_device *dev; uint32_t index; struct i2c_adapter adapter; }; struct nv50_i2c_channel *nv50_i2c_channel_create(struct drm_device *dev, uint32_t index); void nv50_i2c_channel_destroy(struct nv50_i2c_channel *chan); #endif /* __NV50_I2C_H__ */ AL; switch (bof->type) { case BOF_TYPE_NULL: if (bof->size) return -EINVAL; break; case BOF_TYPE_STRING: case BOF_TYPE_INT32: case BOF_TYPE_BLOB: r = fwrite(bof->value, bof->size - 12, 1, file); if (r != 1) return -EINVAL; break; case BOF_TYPE_OBJECT: case BOF_TYPE_ARRAY: for (i = 0; i < bof->array_size; i++) { r = bof_file_write(bof->array[i], file); if (r) return r; } break; default: return -EINVAL; } return 0; } int bof_dump_file(bof_t *bof, const char *filename) { unsigned i; int r = 0; if (bof->file) { fclose(bof->file); bof->file = NULL; } bof->file = fopen(filename, "w"); if (bof->file == NULL) { fprintf(stderr, "%s failed to open file %s\n", __func__, filename); r = -EINVAL; goto out_err; } r = fseek(bof->file, 0L, SEEK_SET); if (r) { fprintf(stderr, "%s failed to seek into file %s\n", __func__, filename); goto out_err; } r = fwrite(&bof->type, 4, 1, bof->file); if (r != 1) goto out_err; r = fwrite(&bof->size, 4, 1, bof->file); if (r != 1) goto out_err; r = fwrite(&bof->array_size, 4, 1, bof->file); if (r != 1) goto out_err; for (i = 0; i < bof->array_size; i++) { r = bof_file_write(bof->array[i], bof->file); if (r) return r; } out_err: fclose(bof->file); bof->file = NULL; return r; }