Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
/* $NetBSD: podulebus.c,v 1.34 2022/05/30 09:56:02 andvar Exp $ */

/*
 * Copyright (c) 1994-1996 Mark Brinicombe.
 * Copyright (c) 1994 Brini.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Brini.
 * 4. The name of the company nor the name of the author may be used to
 *    endorse or promote products derived from this software without specific
 *    prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * RiscBSD kernel project
 *
 * podulebus.c
 *
 * Podule probe and configuration routines
 *
 * Created      : 07/11/94
 */

#include <sys/param.h>

__KERNEL_RCSID(0, "$NetBSD: podulebus.c,v 1.34 2022/05/30 09:56:02 andvar Exp $");

#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/kmem.h>
#include <sys/device.h>
#include <uvm/uvm_extern.h>
#include <machine/io.h>
#include <machine/intr.h>
#include <machine/bootconfig.h>
#include <machine/pmap.h>
#include <arm/iomd/iomdreg.h>
#include <arm/iomd/iomdvar.h>
#include <acorn32/podulebus/podulebus.h>
#include <dev/podulebus/podules.h>
#include <dev/podulebus/podule_data.h>

#include "locators.h"

#define WriteByte(a, b) \
    *((volatile unsigned char *)(a)) = (b)
#define ReadByte(a) \
    (*((volatile unsigned char *)(a)))

/* Array of podule structures, one per possible podule */

podule_t podules[MAX_PODULES + MAX_NETSLOTS];

extern struct bus_space podulebus_bs_tag;

/* Declare prototypes */

u_int poduleread(u_int, int);
int podulebusmatch(device_t, cfdata_t, void *);
void podulebusattach(device_t, device_t, void *);
int podulebusprint(void *, const char *);
int podulebussubmatch(device_t, cfdata_t, const int *, void *);
void podulechunkdirectory(podule_t *);
void podulescan(device_t);

/*
 * int podulebusmatch(device_t parent, void *match, void *aux)
 *
 * Probe for the podule bus. Currently all this does is return 1 to
 * indicate that the podule bus was found.
 */
 
int
podulebusmatch(device_t parent, cfdata_t cf, void *aux)
{
	switch (IOMD_ID) {
	case RPC600_IOMD_ID:
	case ARM7500_IOC_ID:
	case ARM7500FE_IOC_ID:
		return(1);
	}
	return (0);
}


int
podulebusprint(void *aux, const char *name)
{
	struct podule_attach_args *pa = aux;

	if (name)
		aprint_normal("podule at %s", name);
	if (pa->pa_podule->slottype == SLOT_POD)
		aprint_normal(" slot %d", pa->pa_podule_number);
	else if (pa->pa_podule->slottype == SLOT_NET)
		aprint_normal(" [ netslot %d ]",
		    pa->pa_podule_number - MAX_PODULES);
#ifdef DIAGNOSTIC
	else
		panic("Invalid slot type");
#endif

	return (UNCONF);
}


int
podulebussubmatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
{
	struct podule_attach_args *pa = aux;

	/* Return priority 0 or 1 for wildcarded podule */

	if (cf->cf_loc[PODULEBUSCF_SLOT] == PODULEBUSCF_SLOT_DEFAULT)
		return(config_match(parent, cf, aux));

	/* Return higher priority if we match the specific podule */

	else if (cf->cf_loc[PODULEBUSCF_SLOT] == pa->pa_podule_number)
		return(config_match(parent, cf, aux) * 8);

	/* Fail */
	return(0);
}


#if 0
void
dump_podule(podule_t *podule)
{
	printf("podule%d: ", podule->podulenum);
	printf("flags0=%02x ", podule->flags0);
	printf("flags1=%02x ", podule->flags1);
	printf("reserved=%02x ", podule->reserved);
	printf("product=%02x ", podule->product);
	printf("manufacturer=%02x ", podule->manufacturer);
	printf("country=%02x ", podule->country);
	printf("irq_addr=%08x ", podule->irq_addr);
	printf("irq_mask=%02x ", podule->irq_mask);
	printf("fiq_addr=%08x ", podule->fiq_addr);
	printf("fiq_mask=%02x ", podule->fiq_mask);
	printf("fast_base=%08x ", podule->fast_base);
	printf("medium_base=%08x ", podule->medium_base);
	printf("slow_base=%08x ", podule->slow_base);
	printf("sync_base=%08x ", podule->sync_base);
	printf("mod_base=%08x ", podule->mod_base);
	printf("easi_base=%08x ", podule->easi_base);
	printf("attached=%d ", podule->attached);
	printf("slottype=%d ", podule->slottype);
	printf("podulenum=%d ", podule->podulenum);
	printf("description=%s ", podule->description);
	printf("\n");
}
#endif

void
podulechunkdirectory(podule_t *podule)
{
	u_int address;
	u_int id;
	u_int size;
	u_int addr;
	int loop;
	int done_f5;

	done_f5 = 0;	
	address = 0x40;

	do {
		id = podule->read_rom(podule->sync_base, address);
		size = podule->read_rom(podule->sync_base, address + 4);
		size |= (podule->read_rom(podule->sync_base, address + 8) << 8);
		size |= (podule->read_rom(podule->sync_base, address + 12) << 16);
		if (id == 0xf5) {
			addr = podule->read_rom(podule->sync_base, address + 16);
			addr |= (podule->read_rom(podule->sync_base, address + 20) << 8);
			addr |= (podule->read_rom(podule->sync_base, address + 24) << 16);
			addr |= (podule->read_rom(podule->sync_base, address + 28) << 24);
			if (addr < 0x800 && done_f5 == 0) {
				done_f5 = 1;
				for (loop = 0; loop < size; ++loop) {
					if (loop < PODULE_DESCRIPTION_LENGTH) {
						podule->description[loop] =
						    podule->read_rom(podule->sync_base, (addr + loop)*4);
						podule->description[loop + 1] = 0;
					}
				}
			}
		}
#ifdef DEBUG_CHUNK_DIR
		if (id == 0xf5 || id == 0xf1 || id == 0xf2 || id == 0xf3 || id == 0xf4 || id == 0xf6) {
			addr = podule->read_rom(podule->sync_base, address + 16);
			addr |= (podule->read_rom(podule->sync_base, address + 20) << 8);
			addr |= (podule->read_rom(podule->sync_base, address + 24) << 16);
			addr |= (podule->read_rom(podule->sync_base, address + 28) << 24);
			printf("<%04x.%04x.%04x.%04x>", id, address, addr, size);
			if (addr < 0x800) {
				for (loop = 0; loop < size; ++loop) {
					printf("%c", podule->read_rom(podule->sync_base, (addr + loop)*4));
				}
				printf("\\n\n");
			}
		}
#endif
		address += 32;
	} while (id != 0 && address < 0x800);
}


void
poduleexamine(podule_t *podule, device_t dev, int slottype)
{
	struct manufacturer_description *man_desc;
	struct podule_description *pod_desc;

	/* Test to see if the podule is present */

	if ((podule->flags0 & 0x02) == 0x00) {
		podule->slottype = slottype;
		if (slottype == SLOT_NET)
			printf("netslot%d at %s : ", podule->podulenum - MAX_PODULES,
			    device_xname(dev));
		else
			printf("podule%d  at %s : ", podule->podulenum,
			    device_xname(dev));

		/* Is it Acorn conformant ? */

		if (podule->flags0 & 0x80)
			printf("Non-Acorn conformant expansion card\n");
		else {
			int id;

			/* Is it a simple podule ? */

			id = (podule->flags0 >> 3) & 0x0f;
			if (id != 0)
				printf("Simple expansion card <%x>\n", id);
			else {
				/* Scan the chunk directory if present for tags we use */
				if (podule->flags1 & PODULE_FLAGS_CD)
					podulechunkdirectory(podule);

				/* Do we know this manufacturer ? */
				man_desc = known_manufacturers;
				while (man_desc->description) {
					if (man_desc->manufacturer_id ==
					    podule->manufacturer)
						break;
					++man_desc;
				}
				if (!man_desc->description)
					printf("man=%04x   : ", podule->manufacturer);
				else
					printf("%s : ", man_desc->description);

				/* Do we know this product ? */

				pod_desc = known_podules;
				while (pod_desc->description) {
					if (pod_desc->product_id == podule->product)
						break;
					++pod_desc;
				}
				if (!pod_desc->description)
					printf("prod=%04x : ",
					    podule->product);
				else
					printf("%s : ", pod_desc->description);
				printf("%s\n", podule->description);
			}
		}
	}
}


u_int
poduleread(u_int address, int offset)
{

	return(ReadByte(address + offset));
}

void
podulescan(device_t dev)
{
	int loop;
	podule_t *podule;
	u_char *address;
	u_int offset = 0;

	/* Loop round all the podules */

	for (loop = 0; loop < MAX_PODULES; ++loop, offset += SIMPLE_PODULE_SIZE) {
		podule = &podules[loop];
		podule->podulenum = loop;
		podule->attached = 0;
		podule->slottype = SLOT_NONE;
		podule->interrupt = IRQ_PODULE;
		podule->read_rom = poduleread;
		podule->dma_channel = -1;
		podule->dma_interrupt = -1;
		podule->description[0] = 0;

		if (loop == 4) offset += PODULE_GAP;
		address = ((u_char *)SYNC_PODULE_BASE) + offset;
        
		if ((address[0] & 0x02) == 0x00) {
			podule->fast_base = FAST_PODULE_BASE + offset;
			podule->medium_base = MEDIUM_PODULE_BASE + offset;
			podule->slow_base = SLOW_PODULE_BASE + offset;
			podule->sync_base = SYNC_PODULE_BASE + offset;
			podule->mod_base = MOD_PODULE_BASE + offset;
			podule->easi_base = EASI_BASE + loop * EASI_SIZE;
		} else {
			address = ((u_char *)EASI_BASE) + loop * EASI_SIZE;
			if ((address[0] & 0x02) != 0x00)
				continue;

			podule->fast_base = 0;
			podule->medium_base = 0;
			podule->slow_base = 0;
			podule->sync_base = 0;
			podule->mod_base = 0;
			podule->easi_base = EASI_BASE + loop * EASI_SIZE;
		}

		/* XXX - Really needs to be linked to a DMA manager */
		if (IOMD_ID == RPC600_IOMD_ID) {
			switch (loop) {
			case 0:
				podule->dma_channel = 2;
				podule->dma_interrupt = IRQ_DMACH2;
				break;
			case 1:
				podule->dma_channel = 3;
				podule->dma_interrupt = IRQ_DMACH3;
				break;
			}
		}

		/* Get information from the podule header */

		podule->flags0 = address[0];
		if ((podule->flags0 & 0x78) == 0) {
			podule->flags1 = address[4];
			podule->reserved = address[8];
			podule->product = address[12] + (address[16] << 8);
			podule->manufacturer = address[20] + (address[24] << 8);
			podule->country = address[28];
			if (podule->flags1 & PODULE_FLAGS_IS) {
				podule->irq_addr = address[52] + (address[56] << 8) + (address[60] << 16);
				podule->irq_addr += podule->slow_base;
				podule->irq_mask = address[48];
				if (podule->irq_mask == 0)
					podule->irq_mask = 0x01;
				podule->fiq_addr = address[36] + (address[40] << 8) + (address[44] << 16);
				podule->fiq_addr += podule->slow_base;
				podule->fiq_mask = address[32];
				if (podule->fiq_mask == 0)
					podule->fiq_mask = 0x04;
			} else {
				podule->irq_addr = podule->slow_base;
				podule->irq_mask = 0x01;
				podule->fiq_addr = podule->slow_base;
				podule->fiq_mask = 0x04;
			}
		}

		poduleexamine(podule, dev, SLOT_POD);
	}
}


/*
 * void podulebusattach(device_t parent, device_t dev, void *aux)
 *
 * Attach podulebus.
 * This probes all the podules and sets up the podules array with
 * information found in the podule headers.
 * After identifying all the podules, all the children of the podulebus
 * are probed and attached.
 */
  
void
podulebusattach(device_t parent, device_t self, void *aux)
{
	int loop;
	struct podule_attach_args pa;
#if 0
	int easi_time;
	int bit;
#endif
	unsigned int value;
	char argstring[20];

#if 0
	easi_time = IOMD_READ_BYTE(IOMD_ECTCR);
	printf(": easi timings=");
	for (bit = 0x01; bit < 0x100; bit = bit << 1)
		if (easi_time & bit)
			printf("C");
		else
			printf("A");
#endif
	printf("\n");


#if 0 /* XXXJRT */
	/* Ok we need to map in the podulebus */
	/* with the new pmap mappings have to be done when the L1 tables
	 * are built during initarm
	 */
	/* Map the FAST and SYNC simple podules */
	pmap_map_section((vaddr_t)pmap_kernel()->pm_pdir,
	    SYNC_PODULE_BASE & 0xfff00000, SYNC_PODULE_HW_BASE & 0xfff00000,
	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
	cpu_tlb_flushD();
	/* Now map the EASI space */

	for (loop = 0; loop < MAX_PODULES; ++loop) {
		int loop1;
        
		for (loop1 = loop * EASI_SIZE; loop1 < ((loop + 1) * EASI_SIZE);
		    loop1 += L1_S_SIZE)
		pmap_map_section((vaddr_t)pmap_kernel()->pm_pdir,
		    EASI_BASE + loop1, EASI_HW_BASE + loop1,
		    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
	}
	cpu_tlb_flushD();
#endif
	/*
	 * The MEDIUM and SLOW simple podules and the module space will have been
	 * mapped when the IOMD and COMBO we mapped in for the RPC
	 */

	/* Find out what hardware is bolted on */

	podulescan(self); 
	netslotscan(self);

	/* Look for drivers to attach */

	for (loop = 0; loop < MAX_PODULES+MAX_NETSLOTS; ++loop) {
#if 1
		/* Provide backwards compat for a while */
		snprintf(argstring, sizeof(argstring), "podule%d.disable", loop);
		if (get_bootconf_option(boot_args, argstring,
		    BOOTOPT_TYPE_BOOLEAN, &value)) {
			if (value) {
				if (podules[loop].slottype != SLOT_NONE)
					printf("podule%d: Disabled\n", loop);
				continue;
			}
 		}
#endif
 		snprintf(argstring, sizeof(argstring), "podule%d=", loop);
 		if (get_bootconf_option(boot_args, argstring,
 		    BOOTOPT_TYPE_HEXINT, &value)) {
			/* Override the ID */
			podules[loop].manufacturer = value >> 16;
 			podules[loop].product = value & 0xffff;
			/* Any old description is now wrong */
			podules[loop].description[0] = 0;
			if (value != 0xffff) {
				printf("podule%d: ID overridden man=%04x prod=%04x\n",
				    loop, podules[loop].manufacturer,
				    podules[loop].product);
				podules[loop].slottype = SLOT_POD;
				pa.pa_podule_number = loop;
				pa.pa_ih = pa.pa_podule_number;
				pa.pa_podule = &podules[loop];
				pa.pa_iot = &podulebus_bs_tag;
				config_found(self, &pa, podulebusprint,
				    CFARGS(.submatch = podulebussubmatch));
				continue;
			}
			if (value == 0xffff) {
				printf("podule%d: Disabled\n", loop);
				continue;
			}
		}
		
		if (podules[loop].slottype != SLOT_NONE) {
			pa.pa_podule_number = loop;
			pa.pa_ih = pa.pa_podule_number;
			pa.pa_podule = &podules[loop];
			pa.pa_iot = &podulebus_bs_tag;
			config_found(self, &pa, podulebusprint,
			    CFARGS(.submatch = podulebussubmatch));
		}
	}
}


CFATTACH_DECL_NEW(podulebus, 0,
	podulebusmatch, podulebusattach, NULL, NULL);

/* Useful functions that drivers may share */

/*
 * Match a podule structure with the specified parameters
 * Returns 0 if the match failed
 * The required_slot is not used at the moment.
 */

int
matchpodule(struct podule_attach_args *pa, int manufacturer, int product, int required_slot)
{
	if (pa->pa_podule->attached)
		panic("podulebus: Podule already attached");

	if (IS_PODULE(pa, manufacturer, product))
		return(1);

	return(0);
}

void *
podulebus_irq_establish(podulebus_intr_handle_t ih,
	int ipl, int (*func)(void *), void *arg, struct evcnt *ev)
{

	/* XXX We don't actually use the evcnt supplied, just its name. */
	return intr_claim(podules[ih].interrupt, ipl, ev->ev_group, func,
	    arg);
}

/*
 * Generate a bus_space_tag_t with the specified address-bus shift.
 */
void
podulebus_shift_tag(bus_space_tag_t tag, u_int shift, bus_space_tag_t *tagp)
{

	/*
	 * For the podulebus, the bus tag cookie is the shift to apply
	 * to registers, so duplicate the bus space tag and change the
	 * cookie.
	 */

	/* XXX never freed, but podules are never detached anyway. */
        *tagp = kmem_alloc(sizeof(struct bus_space), KM_SLEEP);
	**tagp = *tag;
	(*tagp)->bs_cookie = (void *)shift;
}

int
podulebus_initloader(struct podulebus_attach_args *pa)
{

	/* No loader support at present on arm32, so always fail. */
	return -1;
}

int
podloader_readbyte(struct podulebus_attach_args *pa, u_int addr)
{

	panic("podloader_readbyte");
}

void
podloader_writebyte(struct podulebus_attach_args *pa, u_int addr, int val)
{

	panic("podloader_writebyte");
}

void
podloader_reset(struct podulebus_attach_args *pa)
{

	panic("podloader_reset");
}

int
podloader_callloader(struct podulebus_attach_args *pa, u_int r0, u_int r1)
{

	panic("podloader_callloader");
}

/* End of podulebus.c */