static void hw_iobus_attach_address_callback(device *me, attach_type type, int space, unsigned_word addr, unsigned nr_bytes, access_type access, device *client) /*callback/default*/ { int attach_space; unsigned_word attach_address; /* sanity check */ if (space != 0) device_error(me, "invalid space (%d) specified by %s", space, device_path(client)); /* get the bus address */ device_address_to_attach_address(device_parent(me), device_unit_address(me), &attach_space, &attach_address, me); if (addr < attach_address) device_error(me, "Invalid attach address 0x%lx", (unsigned long)addr); device_attach_address(device_parent(me), type, attach_space, addr, nr_bytes, access, client); }
static void hw_disk_init_address(device *me) { hw_disk_device *disk = device_data(me); unsigned_word address; int space; const char *name; /* attach to the parent. Since the bus is logical, attach using just the unit-address (size must be zero) */ device_address_to_attach_address(device_parent(me), device_unit_address(me), &space, &address, me); device_attach_address(device_parent(me), attach_callback, space, address, 0/*size*/, access_read_write_exec, me); /* Tell the world we are a disk. */ device_add_string_property(me, "device_type", "block"); /* get the name of the file specifying the disk image */ disk->name_index = 0; disk->nr_names = device_find_string_array_property(me, "file", disk->name_index, &name); if (!disk->nr_names) device_error(me, "invalid file property"); /* is it a RO device? */ disk->read_only = (strcmp(device_name(me), "disk") != 0 && strcmp(device_name(me), "floppy") != 0 && device_find_property(me, "read-only") == NULL); /* now open it */ open_disk_image(me, disk, name); }
static void hw_sem_init_data(device *me) { hw_sem_device *sem = (hw_sem_device*)device_data(me); const device_unit *d; int status; union semun help; /* initialize the properties of the sem */ if (device_find_property(me, "key") == NULL) error("sem_init_data() required key property is missing\n"); if (device_find_property(me, "value") == NULL) error("sem_init_data() required value property is missing\n"); sem->key = (key_t) device_find_integer_property(me, "key"); DTRACE(sem, ("semaphore key (%d)\n", sem->key) ); sem->initial = (int) device_find_integer_property(me, "value"); DTRACE(sem, ("semaphore initial value (%d)\n", sem->initial) ); d = device_unit_address(me); sem->physical_address = d->cells[ d->nr_cells-1 ]; DTRACE(sem, ("semaphore physical_address=0x%x\n", sem->physical_address)); /* Now to initialize the semaphore */ if ( sem->initial != -1 ) { sem->id = semget(sem->key, 1, IPC_CREAT | 0660); if (sem->id == -1) error("hw_sem_init_data() semget failed\n"); help.val = sem->initial; status = semctl( sem->id, 0, SETVAL, help ); if (status == -1) error("hw_sem_init_data() semctl -- set value failed\n"); } else { sem->id = semget(sem->key, 1, 0660); if (sem->id == -1) error("hw_sem_init_data() semget failed\n"); } sem->count = semctl( sem->id, 0, GETVAL, help ); if (sem->count == -1) error("hw_sem_init_data() semctl -- get value failed\n"); DTRACE(sem, ("semaphore OS value (%d)\n", sem->count) ); }
split_find_device(device *current, name_specifier *spec) { /* strip off (and process) any leading ., .., ./ and / */ while (1) { if (strncmp(spec->path, "/", strlen("/")) == 0) { /* cd /... */ while (current != NULL && device_parent(current) != NULL) current = device_parent(current); spec->path += strlen("/"); } else if (strncmp(spec->path, "./", strlen("./")) == 0) { /* cd ./... */ current = current; spec->path += strlen("./"); } else if (strncmp(spec->path, "../", strlen("../")) == 0) { /* cd ../... */ if (current != NULL && device_parent(current) != NULL) current = device_parent(current); spec->path += strlen("../"); } else if (strcmp(spec->path, ".") == 0) { /* cd . */ current = current; spec->path += strlen("."); } else if (strcmp(spec->path, "..") == 0) { /* cd . */ if (current != NULL && device_parent(current) != NULL) current = device_parent(current); spec->path += strlen(".."); } else break; } /* now go through the path proper */ if (current == NULL) { split_device_name(spec); return NULL; } while (split_device_name(spec)) { device *child; for (child = device_child(current); child != NULL; child = device_sibling(child)) { if (strcmp(spec->name, device_name(child)) == 0) { if (spec->unit == NULL) break; else { device_unit phys; device_decode_unit(current, spec->unit, &phys); if (memcmp(&phys, device_unit_address(child), sizeof(device_unit)) == 0) break; } } } if (child == NULL) return current; /* search failed */ current = child; } return current; }