Position a rack in the center of the oven and preheat to 400 degrees F. Butter a 2-quart glass or ceramic baking dish.
Heat the oil in a heavy large skillet over medium-high heat. Add the onions and cook until tender and golden, about 10 minutes. Add the garlic and stir 1 minute. Add the cream, broth, rosemary, salt and pepper. Remove the pan from the heat.
Mix all the grated cheeses together in a medium bowl.
Mix the yams and potatoes together in a medium bowl.
Arrange one-third of the potato mixture in the bottom of the prepared baking dish. Sprinkle with one-third of the cheese mixture. Repeat the layers twice more ending with a layer of the cheese mixture. Pour the cream mixture over the layers and cover the pan with foil.
Bake the gratin until the potatoes are almost tender, about 45 minutes. Remove the foil and continue to bake until the potatoes are tender and golden on top, 20 to 25 minutes longer. Remove from the oven and let the gratin rest, 10 minutes. Sprinkle with the chopped parsley, if using, and serve.
Recipe courtesy of Giada De Laurentiis